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
interfaceA{a: number;}interfaceB{b: number;}functionisA(arg: any): arg is A{returnarg.a!==undefined;}functiontest(arg: A|B){if(isA(arg)){console.log(arg.a);}else{console.log(arg.b);}}functiontestThis(this: A|B){if(isA(this)){console.log(this.a);}else{console.log(this.b);}}
Expected behavior: arg is of type A or B in the function test, after passing the type guard. this is of type A or B in the function testThis, after passing the type guard.
Actual behavior: arg is the correct type. this remains of type A | B, so typescript reports an error on both calls to this.a and this.b.
TypeScript Version: 2.2.1
Code
Expected behavior:
arg
is of typeA
orB
in the functiontest
, after passing the type guard.this
is of typeA
orB
in the functiontestThis
, after passing the type guard.Actual behavior:
arg
is the correct type.this
remains of typeA | B
, so typescript reports an error on both calls tothis.a
andthis.b
.This can be seen in the playground here.
The text was updated successfully, but these errors were encountered: