You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I am pretty sure this is covered in a number of other tickets, but don't have the time for the search foo...
Essentially instances of Foo and instances of Bar are structurally the same. TypeScript's type system for various reasons is structurally typed, and because Foo and Bar are of compatible public structures, their instances are assignable to each other. instanceof is the only nominal type checking in ECMAScript, but currently TypeScript still treats it as a structural guard, because of the way its type system works. For TypeScript 2.1 the team continue to look at ways of dealing with instanceof in a nominal way, but allow the rest of the type system to work as designed.
So what is happening is that using instance of, you are eliminate both Foo and Bar from the type and resulting in a never type. In order to work around this current limitation, you would need two classes where their public structure is incompatible for TypeScript to be able to discriminate them.
TypeScript Version: nightly (2.1.0-dev.20160831)
Code
Expected behavior:
No errors or at least error
Property 'baz' does not exist on type 'Foo|Bar'
.Actual behavior:
Error
Property 'baz' does not exist on type 'never'.
The text was updated successfully, but these errors were encountered: