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
{{ message }}
Repository navigation
Narrowed union types loosened within closures #19683
classA{name: string;}classB{age: number;}letx: A|B;if(xinstanceofA){console.log(x.name);// ok: x has type AsetTimeout(()=>{console.log(x.name);// ** COMPILE ERROR: x has type A | B here});}else{console.log(x.age);// ok: x has type B heresetTimeout(()=>{console.log(x.age);// ** COMPILE ERROR: x has type A | B here});}
In my.situation (and indeed the repro) it is not possible for x to have been mutated, but I can see that in general case that's harder to work out definitively. Thanks for the const tip.
Activity
myitcv commentedon Nov 3, 2017
In my.situation (and indeed the repro) it is not possible for
xto have been mutated, but I can see that in general case that's harder to work out definitively. Thanks for theconsttip.