-
-
Notifications
You must be signed in to change notification settings - Fork 2.8k
Bug: [no-unnecessary-type-parameters] Counts type parameter references in body irrelevant to the signature #9735
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
Comments
@JoshuaKGoldberg Could you please explain why type parameter usages in the implementation should be ignored? Is |
Type parameters in the body is type checked using the base constraint of the parameter, so ...In other words, if the rule reports, then you could remove the type parameter and rewrite the function body, and achieve a function that's as sound as before. |
Aren't they non-equivalent when assigning to function f<T>() {
const x: T = ""
// ^
// Type 'string' is not assignable to type 'T'.
// 'T' could be instantiated with an arbitrary type which could be unrelated to 'string'.
} |
In a way, they are the widest possible type when assigned from and the narrowest possible type when assigned to. I realized how tricky it is so hopefully my second paragraph is a better phrasing of what I meant. |
Putting it another way: A type parameter Note: for unbounded type parameter (eg Footnotes
|
Before You File a Bug Report Please Confirm You Have Done The Following...
Playground Link
https://typescript-eslint.io/play/#ts=5.5.2&fileType=.tsx&code=GYVwdgxgLglg9mABMOcA8AVAfACgPoBciGAlIgN4BQiiECAzlIgB5EaIC8iYIANrwEIA3NVoMmATzadufQSIC%2BlIA&eslintrc=N4KABGBEBOCuA2BTAzpAXGUEKQAIBcBPABxQGNoBLY-AWhXkoDt8B6Jge1tiacTJTIAhtEK0ipWsRFCAtonyJoqDJCXQO0SODABfELqA&tsconfig=N4KABGBEDGD2C2AHAlgGwKYCcDyiAuysAdgM6QBcYoEEkJemy0eAcgK6qoDCAFutAGsylBm3TgwAXxCSgA&tokens=false
Repro Code
ESLint Config
tsconfig
Expected Result
T
should be marked as an unnecessary type parameter. It's only used once in the type signature.Actual Result
No report.
Additional Info
Repro case courtesy of @That-Guy977's #9664 (comment), thanks!
💖
The text was updated successfully, but these errors were encountered: