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
interfaceTrue{value: true;trueString: string;}interfaceFalse{value: false;falseString: string;}typeTrueOrFalse=True|False;letx: TrueOrFalse;if(!x.value){// DOES NOT COMPILE:// Property 'falseString' does not exist on type 'TrueOrFalse'.// Property 'falseString' does not exist on type 'True'.x.falseString;}if(x.value){x.trueString;}else{// SAME ERROR AS ABOVEx.falseString;}if(x.value===false){// WORKSx.falseString;}if(x.value===true){x.trueString;}else{// WORKSx.falseString;}
Expected behavior:
Discriminated union is narrowed within falsy conditional blocks.
Actual behavior:
Discriminated union is not narrowed within (!falsy) conditional block, or within else block of a (truthy) conditional.
TypeScript Version: 3.0 (current Playground)
Search Terms: Discriminated union falsy false
Code
Expected behavior:
Discriminated union is narrowed within falsy conditional blocks.
Actual behavior:
Discriminated union is not narrowed within (!falsy) conditional block, or within
else
block of a (truthy) conditional.Playground Link:
http://www.typescriptlang.org/play/#src=interface%20True%20%7B%0D%0A%20%20%20%20value%3A%20true%3B%0D%0A%20%20%20%20trueString%3A%20string%3B%0D%0A%7D%0D%0Ainterface%20False%20%7B%0D%0A%20%20%20%20value%3A%20false%3B%0D%0A%20%20%20%20falseString%3A%20string%3B%0D%0A%7D%0D%0A%0D%0Atype%20TrueOrFalse%20%3D%20True%20%7C%20False%3B%0D%0Alet%20x%3A%20TrueOrFalse%3B%0D%0A%0D%0Aif%20(!x.value)%20%7B%0D%0A%20%20%20%20%2F%2F%20DOES%20NOT%20COMPILE%3A%0D%0A%20%20%20%20%2F%2F%20Property%20'falseString'%20does%20not%20exist%20on%20type%20'TrueOrFalse'.%0D%0A%20%20%20%20%2F%2F%20%20%20Property%20'falseString'%20does%20not%20exist%20on%20type%20'True'.%0D%0A%20%20%20%20x.falseString%3B%0D%0A%7D%0D%0A%0D%0Aif%20(x.value)%20%7B%0D%0A%20%20%20%20x.trueString%3B%0D%0A%7D%20else%20%7B%0D%0A%20%20%20%20%2F%2F%20SAME%20ERROR%20AS%20ABOVE%0D%0A%20%20%20%20x.falseString%3B%0D%0A%7D%0D%0A%0D%0Aif%20(x.value%20%3D%3D%3D%20false)%20%7B%0D%0A%20%20%20%20%2F%2F%20WORKS%0D%0A%20%20%20%20x.falseString%3B%0D%0A%7D%0D%0A%0D%0Aif%20(x.value%20%3D%3D%3D%20true)%20%7B%0D%0A%20%20%20%20x.trueString%3B%0D%0A%7D%20else%20%7B%0D%0A%20%20%20%20%2F%2F%20WORKS%0D%0A%20%20%20%20x.falseString%3B%0D%0A%7D%0D%0A
Related Issues:
None found.
The text was updated successfully, but these errors were encountered: