-
Notifications
You must be signed in to change notification settings - Fork 12.6k
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
Callback parameter inference not working when part of an inferred tuple type #52047
Comments
You can implement this one with reverse mapped types: TS playground |
Discussed a bit in an external thread - mapped types may not work for the use case where each element in the tuple has multiple type parameters to infer (updated the second playground link in the issue description to reflect this example) |
As mentioned in that other thread - I strongly believe that this proposal would make it way easier to implement such types. With that in place, we could reuse the "reverse mapped types" technique presented in the playground above to infer multiple "generics" per tuple element (where each "generic" would just be a property of the inferred element). |
This one will be extremely hard to fix for outside contributors without a deep understanding of the internals of inference, contextual typing, etc. The problem is that a source object with context-sensitive functions starts as a Fixing this would require the compiler to become smarter about "partially inferrable types". I actually managed to fix this locally but, as I expected, the It's actually interesting here that reverse-mapped types can infer from partially inferrable types ( |
Bug Report
Been experiencing the below problem with
no-implicit-any
on callback parameter types, when the callback is part of a tuple function-argument, whose type I am inferring.Was thinking it could be a case of unsupported/incorrect usage on my end, however the type suggestion does appear to be correct on-mouse-hover, so wondering if there's something extra at play.
Might be somewhat related to #44476 but not sure.
🔎 Search Terms
Tuple, callback, generic, inference
🕗 Version & Regression Information
This is the behavior in every version I tried since 4.0 that brought support for variadic tuples, and I reviewed the FAQ for entries about generics/tuples/callbacks
⏯ Playground Link
Playground link with relevant code
(for context, if the above example feels a bit contrived: the actual use-case involves typing/checking a function argument that can be a variadic tuple with multiple complex elements, using a more complex utility type. If interested here's a second playground link with the whole shebang - but in the first one I've tried to pare it down to the most basic example with just 1 element on the tuple)
💻 Code
🙁 Actual behavior
Handler complains about no-implicit-any, even though type-suggestion work as expected, and type-checking works if you add the param type explicitly.
🙂 Expected behavior
Handler parameter type can be inferred automatically; no no-implicit-any complaints.
The text was updated successfully, but these errors were encountered: