Skip to content

Bug: [no-unnecessary-type-constraint] False positive for generics on arrow functions in .mts files #5449

Closed
@spalger

Description

@spalger

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.

Issue Description

When using the new (as of TS 4.7) .mts file extension the const foo = <T>() => ... syntax for generic arguments is reserved similar to JSX files. The suggestion from tsc recommends defining an explicit constraint:

image

Since my function doesn't need or nor do I want a type constraint, but I need one for the syntax, I reached for the noop constraint of extends any, but then I was violating the no-unnecessary-type-constraint rule.

image

In this case, with the .mts extension and it's limited syntax I think it's unfair to say it "doesn't do anything and is unnecessary".

Reproduction Repository Link

https://github.com/spalger/reproduce-issues/tree/ts-eslint-no-unnecessary-type-constraint

Repro Steps

  1. clone the repo with --branch

    git clone git@github.com:spalger/reproduce-issues.git --branch ts-eslint-no-unnecessary-type-constraint

  2. npm i

  3. npm run lint

Versions

package version
@typescript-eslint/eslint-plugin 5.33.0
@typescript-eslint/parser 5.33.0
TypeScript 4.7.4
ESLint 8.21.0
node 18.7.0

Metadata

Metadata

Assignees

No one assigned

    Labels

    accepting prsGo ahead, send a pull request that resolves this issuebugSomething isn't workinggood first issueGood for newcomers

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions