-
-
Notifications
You must be signed in to change notification settings - Fork 669
Improve inferring generic parameters #839
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
Conversation
Could this PR also potentially fix #837? |
Appears to be a different issue caused by ordering, but this PR might help to solve it. |
Will be great! |
The other issue should be resolved as well with the last commit. Now infers all types first while updating to compatible types, and only then does another pass to do the actual resolving. |
It will be great inferring type from argument as well. For example: const arr: i32[] = [1,2,3];
arr.reduce<i32>(((prev: i32, current: i32): i32 => prev + current), 0); // but `0` already infer as `i32` Will be great don't specify arr.reduce(((prev: i32, current: i32): i32 => prev + current), 0);
// other example:
arr.reduce(((prev, current) => prev && current), false);
// infer as arr.reduce<bool>(((prev: i32, current: i32): bool => prev && current), false); |
Last commit should fix issues with arr.reduce(((prev: i32, current: i32): i32 => prev + current), 0); inferring arr.reduce(((prev, current) => prev && current != 0), false); yet. What we would have to do there is to have a special case for function expressions without any types that just so happen to be fully specified by inferring other types, creating a new function signature with types that then becomes resolved - or something along those lines. |
Wait, arr.reduce(((prev, current) => prev && current != 0), false); appears to compile now. I guess the other logic we have for function expressions without types can pick this up now since the code now uses |
Great! Well done! |
potentially fixes #219
potentially fixes #837
This makes use of the new resolver infrastructure to improve inferring generic types, like in
by first obtaining the type of the respective argument containing a type parameter and then matching it, including encapsulated type parameters, against the template.
Still feels a bit fragile as if I'd missed something, so if you spot an issue, let me know :)