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
Search Terms: conditional type eager, conditional type narrowing
Code
typeFooHelper<X>=(arg1: X,arg2: Xextends0 ? number : string)=>void;typeFoo=FooHelper<0|1>;letx: number;constfoo: Foo=(t,d)=>{if(t===0){x=d;}}
Expected behavior:
No errors, t has type 0 | 1 in the function body which gets narrowed to just 0 in the body of the if statement. In the if statement, d should have type number, because we know that t has to have type 0.
Actual behavior:
Type 'string | number' is not assignable to type 'string'.
TypeScript Version: 3.7.x-dev.201xxxxx
Search Terms: conditional type eager, conditional type narrowing
Code
Expected behavior:
No errors,
thas type0 | 1in the function body which gets narrowed to just0in the body of the if statement. In the if statement,dshould have type number, because we know thatthas to have type0.Actual behavior:
Type 'string | number' is not assignable to type 'string'.
Playground Link: https://www.typescriptlang.org/play/?ts=3.7-Beta#code/C4TwDgpgBAYg9nAEhANpATgHgBoD4oC8UAFAIboDmAjAFxTYA0U5FATHdlBAB7AQB2AEwDOUAAxQA-FGHB0AS34UodfgFcAtgCMI6AJSF8ANzjzBAbgBQoSLASE7SVBkwSAPlCq4rllBGBQ3HSyCkpWAMZw-LJQAGYIdPBwDsTATIIGBPgA3pZQ+VDysamEBERiBtmBDhZQAL6WdUA
Related Issues: not really