Skip to content

Bug: [explicit-function-return-type] typed function expression flagged despite allowTypedFunctionExpressions: true #8023

Closed
@AndreasHae

Description

@AndreasHae

Before You File a Bug Report Please Confirm You Have Done The Following...

  • I have tried restarting my IDE and the issue persists.
  • I have updated to the latest version of the packages.
  • I have searched for related issues and found none that matched my issue.
  • I have read the FAQ and my problem is not listed.

Playground Link

https://typescript-eslint.io/play/#ts=5.3.2&fileType=.ts&code=JYOwLgpgTgZghgYwgAgPICMBWEFgOrBgAWAYgK4i7AD2IyA3gFDLIwUIBcyAFAB5cgyAW3TQAlMgC8APmSCR0RgF9GjBLQDOYZNSwBBDQDU4UYHHQAbCFwzZcBYuUpgadSQ2at2XXlNm%2BAamQARmVVdRAtZBMoA2NTcysbLBx8QlJ2F1oAbQBdKWRszyYWFjZKHz9kQJDPFVzwizgNDWQAUV44IQAHKw8WXUwDEmAICwATZLs0x0zXApLS8s5qqprQlhVPAHpt6IsLHRhkYhRzagA3FAB3aigAa2jWiF5u1Ihx1RYY4dGJqdSDgyzlceQKRVK-UhyF2JyIwFaGiI1DIE2Qon2Fmo1w%2Bnkhy0qMlWQQ2pRULAaKiAA&eslintrc=N4KABGBEBOCuA2BTAzpAXGUEKQAIBcBPABxQGNoBLY-AWhXkoDt8B6RAD2MbMroDNYTMvkoB7JrWiJ8saJKKl0YANrhsORNGhjokADTqNWDdkgBDePDEB3AColEAEwBiQkeKYBRLtOTJPVAx8OEQjbABfcIBddSiIoA&tsconfig=&tokens=false

Repro Code

interface ObjectWithFunction {
  func: (x: number) => number
}

const objAsVariable: ObjectWithFunction = {
  func: x => x + 1
}

const arrAsVariable: ObjectWithFunction[] = [
  {
    func: x => x + 1
  }
]

class Example {
  objAsField: ObjectWithFunction = {
    func: x => x + 1
  }

  // all of the above work as expected

  arrAsField: ObjectWithFunction[] = [
    {
      // this should be allowed
      func: x => x + 1
    }
  ]
}

ESLint Config

{
  "rules": {
    "@typescript-eslint/explicit-function-return-type": [
      "error",
      {
        "allowTypedFunctionExpressions": true
      }
    ]
  }
}

tsconfig

No response

Expected Result

The given code sample should lint without errors.

Actual Result

There is a linting error on line 26: Missing return type on function. 25:7 - 25:13, despite the option allowTypedFunctionExpressions: true.

Additional Info

I would have liked to check on which version this started occurring, but the online playground apparently doesn't support selecting the tseslint version.

Metadata

Metadata

Assignees

No one assigned

    Labels

    accepting prsGo ahead, send a pull request that resolves this issuebugSomething isn't workingpackage: eslint-pluginIssues related to @typescript-eslint/eslint-plugin

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions