-
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
Empty type {} gets inferred to without a warning #2511
Comments
When you say you expect an error, you mean because of the failure to find candidates for type arguments, not for any other reason, right? If so, this sounds like a duplicate of #360. |
Yes. Somehow I thought #360 was shipped with 1.4, wasn't it? I saw it my self giving errors in a LKG a while ago. |
No, that relates to if we are unable to find a common supertype as in the following:
|
Sorry for the unrelated question, is the milestone for shipping #360 set? |
Your code looks correct, but maybe you are talking about the case where values is not an |
Well, I think the code is unsound and vulnerable to refactoring. Consider var values /* : A[] */ = [{ isDeliciousPizza: true }];
values.map(notOver(isOkOf)); // <-- still no warnings |
I would also add that the compiler does two odd things with your original repro:
|
Yes, the vulnerability you note is my point exactly. Because |
You can test that out by making |
Well, the whole point it to have
Wouldn't it? May I dare to ask if there is any chance for TS to ever get Hindley Milner sort of type system? |
Perhaps you are asking for us to infer the A for the |
I mean as a fallback. |
I can think of 4 options here:
|
Actually 3 is more complex than I thought. Previously a contextual type could have no effect on a call expression. With this proposal it would. The tricky part is that we'd have to add another condition for fixing type parameters as a result of contextually typing a call expression. |
The other complex thing about it is that it messes with the arity of the signature and the number of arguments being passed, and I can't figure out how that would interact with spread and rest. |
There's a branch that has suggestion 2 called |
I like the best options 1 then 2. |
I'm closing this one since it looks to be covered in #3423. |
@ahejlsberg, I am afraid this request is a related, but separate issue interface A<Z> { z: Z }
declare function fn<X extends A<Z>, Z>(value: X): void;
declare var a: A<number>;
fn(a); // <-- a problem: fn<A<number>, {}> I would like the "inferred" empty type was flagged by the compiler. |
The text was updated successfully, but these errors were encountered: