Skip to content

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

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
4 tasks done
QuixThe2nd opened this issue Jun 11, 2025 · 1 comment
Closed
4 tasks done

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

QuixThe2nd opened this issue Jun 11, 2025 · 1 comment
Labels
bug Something isn't working package: eslint-plugin Issues related to @typescript-eslint/eslint-plugin working as intended Issues that are closed as they are working as intended

Comments

@QuixThe2nd
Copy link

QuixThe2nd commented Jun 11, 2025

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.

@QuixThe2nd QuixThe2nd added bug Something isn't working package: eslint-plugin Issues related to @typescript-eslint/eslint-plugin triage Waiting for team members to take a look labels Jun 11, 2025
@bradzacher
Copy link
Member

This is working as expected - you have created a generic in the function signature for an implementation detail in the function body.

You could update the code to enclose the detail so it does not leak into the signature:

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

@bradzacher bradzacher closed this as not planned Won't fix, can't repro, duplicate, stale Jun 11, 2025
@bradzacher bradzacher added working as intended Issues that are closed as they are working as intended and removed triage Waiting for team members to take a look labels Jun 11, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working package: eslint-plugin Issues related to @typescript-eslint/eslint-plugin working as intended Issues that are closed as they are working as intended
Projects
None yet
Development

No branches or pull requests

2 participants