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
Discriminated union does not narrow based on falsy conditional #27059
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.
Activity
DanielRosenwasser commentedon Sep 13, 2018
Works in
strictNullChecks, and so this is a duplicate of #10564.typescript-bot commentedon Dec 14, 2018
This issue has been marked as a 'Duplicate' and has seen no recent activity. It has been automatically closed for house-keeping purposes.