-
Notifications
You must be signed in to change notification settings - Fork 12.9k
Open
Labels
Fix AvailableA PR has been opened for this issueA PR has been opened for this issueIn DiscussionNot yet reached consensusNot yet reached consensusSuggestionAn idea for TypeScriptAn idea for TypeScript
Description
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.
jtbandes, molisani, arszen123, whzx5byb, cengels and 15 morejoshuakb2
Metadata
Metadata
Assignees
Labels
Fix AvailableA PR has been opened for this issueA PR has been opened for this issueIn DiscussionNot yet reached consensusNot yet reached consensusSuggestionAn idea for TypeScriptAn idea for TypeScript