Skip to content

Bug: [no-unnecessary-type-parameters] false positive when used in the implementation of the method #9828

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
ST-DDT opened this issue Aug 19, 2024 · 3 comments
Closed
4 tasks done
Labels
bug Something isn't working locked due to age Please open a new issue if you'd like to say more. See https://typescript-eslint.io/contributing. package: eslint-plugin Issues related to @typescript-eslint/eslint-plugin working as intended Issues that are closed as they are working as intended

Comments

@ST-DDT
Copy link
Contributor

ST-DDT commented Aug 19, 2024

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.5.4&fileType=.ts&code=KYDwDg9gTgLgBAMwK4DsDGMCWEVxsAZxgB4AVOUfFAEwLiKkxQHMA%2BACgFtgYALCagC44pAJTCGTZnADeAWABQcOGhxE4AQyjM6AXjgByA5rqkA3IuVQeSKLm58BcANSbtBCwoC%2BQA&eslintrc=N4KABGBEBOCuA2BTAzpAXGUEKQAIBcBPABxQGNoBLY-AWhXkoDt8B6Jge1tiacTJTIAhtEK0ipWsRFCAtonyJoqDJCXQO0SODABfELqA&tsconfig=N4XyA&tokens=false

Repro Code

export function test<T extends string>(method: T): string {
  const args = '' as T;
  return method + args;
}

ESLint Config

{
  "rules": {
    "@typescript-eslint/no-unnecessary-type-parameters": "error"
  }
}

tsconfig

{}

Expected Result

No Error

Actual Result

Type parameter T is used only once in the function signature.eslint@typescript-eslint/no-unnecessary-type-parameters

Additional Info

Original Code: https://github.com/faker-js/faker/blob/cc7715bebded681655b95f5afc368cb250a2eadf/test/support/seeded-runs.ts#L172-L192

The error was first observed in v8.1.0 it does not appear in 7.18.0

The rule seems to ignore any usage of the type inside the actual implementation.

@ST-DDT ST-DDT 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 Aug 19, 2024
@JoshuaKGoldberg
Copy link
Member

The rule seems to ignore any usage of the type inside the actual implementation

Indeed, it does! This is intentional 🙂. See #9735. Uses in the function body shouldn't count. The examples in this issue are both good ones of an unsafe as type assertion.

Cross-linking: #9753. This is a good FAQ to have. Thanks for posting!

@JoshuaKGoldberg JoshuaKGoldberg closed this as not planned Won't fix, can't repro, duplicate, stale Aug 19, 2024
@JoshuaKGoldberg JoshuaKGoldberg 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 Aug 19, 2024
@kirkwaiblinger
Copy link
Member

Cross-linking: #9753. This is a good FAQ to have.

I think you mean #9680 🙂

@JoshuaKGoldberg
Copy link
Member

D'oh!

@github-actions github-actions bot added the locked due to age Please open a new issue if you'd like to say more. See https://typescript-eslint.io/contributing. label Sep 3, 2024
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Sep 3, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
bug Something isn't working locked due to age Please open a new issue if you'd like to say more. See https://typescript-eslint.io/contributing. 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

3 participants