-
Notifications
You must be signed in to change notification settings - Fork 12.8k
Wrong inference from function return argument #13118
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
Comments
Something that was a little easier for me to analyze: interface Foo<A> {
a: A;
b: (x: A) => void;
}
declare function canYouInferThis<A>(fn: () => Foo<A>): A;
const result = canYouInferThis(() => ({
a: { BLAH: 33 },
b: x => { }
}))
result.BLAH; |
Any news? Could this still make it for 2.4? |
Right - so this is caused by how we currently perform contextual typing and inference. When we attempt to find the type of the first parameter of I think the "skip context sensitive" pass we perform is generally supposed to alleviate this (so noncontextual inferences like the one here are performed first), but the issue arises because the pass effectively skipped - the entire top-level arrow Now, as it turns out, this is a fixable problem! We need only continue building a type in |
TypeScript Version: 2.2.0-dev.20161221
Code
Expected behavior:
The
A
parameter should be inferred to be{ bla: number }
. It seems completely unambiguous to me.Failing that, I would expect a warning about ambiguous inferred types.
Actual behavior:
The type of
A
is silently inferred to be{}
The text was updated successfully, but these errors were encountered: