-
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
inference strangeness 6 #6611
Comments
This one looks like a contextual typing bug. |
Interestingly, the type parameter is inferred correctly and therefore the type of interface Box<T> {
x: T;
}
declare function f<U>(box: Box<U>, u: U): U;
let handlers: Box<(value: number) => void>;
let z = f(handlers, y => y.length); // expected error: 'length' not in 'number'
|
Working bottom up, I see that Of course the first round discovers that I'll try moving the code that re-initialises the signature before the inference loop. But I expect this will break something else. |
Removing the per-loop reset breaks the compiler badly. An alternate approach is figuring out how to get |
Another case (let me know if you want to open a new issue for this): interface Foo {
init?: () => void;
}
let x: Foo = getX();
if (x.init) {
x.init(); // Works fine
let y = () => {
x.init(); // Object is possibly 'undefined';
}
} |
@unional that's unrelated to this, and behaving as expected. Control-flow-based type analysis doesn't work across function expressions because the value can change at a different point in time. |
Ah, I see. Thanks! 😛 |
The text was updated successfully, but these errors were encountered: