Skip to content

[prefer-function-type] Quick fixing an interface using this causes tsc error #1756

Closed
@cherryblossom000

Description

@cherryblossom000

Repro

{
  "rules": {
    "@typescript-eslint/prefer-function-type": 2
  }
}
interface Interface {(): this}

Expected Result
No error as this can only be used in a class or interface.

Actual Result

/path/to/file.ts
  1:22  error  Interface has only a call signature - use 'type Interface = () => this' instead  @typescript-eslint/prefer-function-type

✖ 1 problem (1 error, 0 warnings)
  1 error and 0 warnings potentially fixable with the `--fix` option.

Additional Info

Running eslint with --fix results in this code:

type Interface = () => this

which causes a tsc error:

file.ts:1:24 - error TS2526: A 'this' type is available only in a non-static member of a class or interface.

1 type Interface = () => this
                         ~~~~


Found 1 error.

Versions

package version
@typescript-eslint/eslint-plugin 2.24.0
@typescript-eslint/parser 2.24.0
TypeScript 3.7.5
ESLint 6.8.0
node 12.11.0
npm 6.11.3

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't workinggood first issueGood for newcomershas prthere is a PR raised to close thispackage: 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