-
-
Notifications
You must be signed in to change notification settings - Fork 514
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
🐛 correctness/noUnusedVariables inferring in unions reports unused variables #565
Comments
This is a tricky case. TypeScript has so many exceptions... Our name resolver has the assumption that a binding is bound to a single declaration. Here @denbezrukov @ematipico any thoughts? Maybe emit different bindings and duplicate the read for every binding? |
I might not know few things, so I might get things wrong. Given this code T extends (infer B)[] | infer B ? B : never Isn't |
Unfortunately not, it is the same declaration :/ If you hover and click on the B reference in TypeScript Playground, you notice that the reference is bound to these two declarations. |
On reflection, we could bind multiple binding identifiers to the same semantic binding. This could solve our problem without destroying all our assumptions. This will require a refactoring of how we identify a semantic binding (for now we identify it using the binding identifier's scope). I am not 100% happy about this because it prevents some optimizations I was planning to do. However, this seems like the best compromise to me. EDIT: we still have an issue by adopting this approach: several syntax nodes are associated to the same semantic binding. This seems really wrong to make more complex the API just for infer bindings... |
Instead of introducing exceptions in the semantic model, we could just ignore |
Yeah, we could try this approach |
Environment information
What happened?
Infering in unions reports unused variables on leading infered type variables.
Expected result
noUnusedVariables shouldn't be reported
Code of Conduct
The text was updated successfully, but these errors were encountered: