Open
Description
openedon Jul 28, 2017
TypeScript Version: 2.4.0
When a variable passes an instanceof
check generic type with constraints on the type parameter, apply to constraints to the variable. There is currently no clean way to handle the following without an explicit cast:
Code
interface Foo {
foo: string;
}
class Bar<T extends Foo> {
constructor(readonly bar: T) {}
}
let a: any;
if (a instanceof Bar) {
a.bar; // <-- a.bar should be 'Foo' instead of 'any'
}
Expected behavior:
a.bar
is inferred as an instance of Foo
.
Actual behavior:
a.bar
is any
This change would only impact type checking, and will not affect compilation output.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment