Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Bug: no-unnecessary-type-parameters false positive #11295

Closed as not planned
Closed as not planned
@QuixThe2nd

Description

@QuixThe2nd

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.8.2&fileType=.tsx&code=MYewdgzgLgBAtgTwGIFczCgS3DAvDAHgBkBDAIwFMAbGCgDygrABMIZoAnTMAcwD4AFFXLUAXDFKUqASjx8YAbwBQMGKEixhUgEzjJ1PDC3UA3CrXgIIKhQB0VEDyEiq26WYC%2BQA&eslintrc=N4KABGBEBOCuA2BTAzpAXGUEKQAIBcBPABxQGNoBLY-AWhXkoDt8B6Jge1tiacTJTIAhtEK0ipWsRFCAtonyJoqDJCXQO0SODABfELqA&tsconfig=N4KABGBEDGD2C2AHAlgGwKYCcDyiAuysAdgM6QBcYoEEkJemy0eAcgK6qoDCAFutAGsylBm3TgwAXxCSgA&tokens=false

Repro Code

const myFunction = <Label extends string>(label: Label) => {
  const label2: Label = label;
  console.log(label2);
}

ESLint Config

module.exports = {
  parser: "@typescript-eslint/parser",
  rules: {
    "@typescript-eslint/no-unnecessary-type-parameters": "error",
  },
};

tsconfig

{
  "compilerOptions": {
    // ...
  }
}

Expected Result

When a type parameter is used only once in the function signature, but also referenced elsewhere in the function, the error should not be thrown.

Actual Result

tseslint doesn't seem to detect the second reference to the type outside the signature.

Additional Info

const label2: Label = label is redundant and has no real world use, but it is the minimum code to reproduce it. I've ran into this error a few times when manipulation objects with a value of type Label[] for example.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't workinglocked due to agePlease open a new issue if you'd like to say more. See https://typescript-eslint.io/contributing.package: eslint-pluginIssues related to @typescript-eslint/eslint-pluginworking as intendedIssues that are closed as they are working as intended

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions