Skip to content
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

[no-unused-vars] v4 false positive with generic inference - with isolated reproduction repo #2459

Closed
3 tasks done
willheslam opened this issue Sep 1, 2020 · 7 comments · Fixed by #2497
Closed
3 tasks done
Assignees
Labels
bug Something isn't working has pr there is a PR raised to close this package: eslint-plugin Issues related to @typescript-eslint/eslint-plugin

Comments

@willheslam
Copy link

  • I have tried restarting my IDE and the issue persists.
  • I have updated to the latest version of the packages.
  • I have read the FAQ and my problem is not listed.

Repro
https://github.com/willheslam/typescript-unused-var-reprod
npm run lint

{
  "rules": {
    "@typescript-eslint/no-unused-vars": 1
  }
}
// eslint-disable-next-line @typescript-eslint/no-explicit-any
type UnionToIntersection<U> = (U extends any ? (k: U) => void : never) extends (
  k: infer I
) => void
  ? I
  : never

Expected Result

No linting issues

Actual Result

3:12  warning  'I' is defined but never used  @typescript-eslint/no-unused-vars

✖ 1 problem (0 errors, 1 warning)

Additional Info

Versions

package version
@typescript-eslint/eslint-plugin 4.0.1
@typescript-eslint/parser 4.0.1
TypeScript 4.0.2
ESLint 7.8.0
node 12.14.1
@willheslam willheslam added package: eslint-plugin Issues related to @typescript-eslint/eslint-plugin triage Waiting for maintainers to take a look labels Sep 1, 2020
@bradzacher bradzacher added bug Something isn't working and removed triage Waiting for maintainers to take a look labels Sep 1, 2020
@bradennapier

This comment has been minimized.

@bradzacher

This comment has been minimized.

@alecf

This comment has been minimized.

@alecf

This comment has been minimized.

@bradzacher

This comment has been minimized.

@blair
Copy link

blair commented Sep 5, 2020

I'm seeing a similar warning in this code:

// https://stackoverflow.com/a/51955852/
type KnownKeys<T> = {
    [K in keyof T]: string extends K ? never : number extends K ? never : K
} extends { [_ in keyof T]: infer U } ? U : never;

gives

  4:35  error  'U' is defined but never used  @typescript-eslint/no-unused-vars

@bradzacher bradzacher self-assigned this Sep 6, 2020
@bradzacher bradzacher added the has pr there is a PR raised to close this label Sep 6, 2020
bradzacher added a commit that referenced this issue Sep 6, 2020
…opes

Fixes #2459

This was a bit tricky. Nested scopes are wack.
bradzacher added a commit that referenced this issue Sep 6, 2020
…opes

Fixes #2459

This was a bit tricky. Nested scopes are wack.
@StasNemy
Copy link

StasNemy commented Sep 21, 2020

export type InferActionsTypes<T> = T extends { [keys: string]: (...args: any[]) => infer U } ? U : never;
'U' is defined but never used @typescript-eslint/no-unused-vars
How about this. Help!

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Oct 22, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
bug Something isn't working has pr there is a PR raised to close this package: eslint-plugin Issues related to @typescript-eslint/eslint-plugin
Projects
None yet
6 participants