-
Notifications
You must be signed in to change notification settings - Fork 12.5k
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
Assert when type inference can't find a common supertype #15116
Comments
I got it to repro on master, but I needed |
The cause of the crash is a mismatch between type inference and type inference error reporting. I'll use a smaller repro with slightly simpler identifiers (my head started hurting while reading declare function f<T extends number | undefined>(a: T, b: T): boolean;
let gut: { n: 12 | undefined };
f(gut.n, 12); // error, invalid supertype Type inference works with these candidates: It looks like there are 3 possible fixes.
(2) is probably the best fix but I'm going to see where (1) happens first. If it's solely within type inference and doesn't leak out into something like contextual typing, it might be worth changing to see how much breaks. (3) just makes the compiler not crash when reporting an incorrect error, so it's not a great fix. |
@ahejlsberg should the rules for widening be special-cased here to widen |
Alternatively, should we not widen the type of the second argument, |
I wrote up the PR for (3) and realised that even if we change the spec, we would still need to unify the implementations of @ahejlsberg I want to discuss the spec with you in person so I can understand the motivation for widening in arguments and not widening in type literals. |
The PR now fixes (2) as well. |
undefined
Fixed by #16439 |
TypeScript Version: 2.2.2
Code
Expected behavior:
Actual behavior:
or if uncommenting out last line and commenting out 2nd to last line:
The text was updated successfully, but these errors were encountered: