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
Expected behavior: No error, Typescript should guess that a variable of type T extends '1' ? '1' : never will never be false, so that NonFalse<TypeWithCondition<T>> is exactly the same than true | (T extends '1' ? '1' : never)
Actual behavior: Error on logNonFalse(a);
Related Issues: none
Code
typeTypeWithCondition<T>=boolean|(Textends'1' ? '1' : never);typeNonFalse<T>=Exclude<T,false>;functionlogNonFalse<T>(b: NonFalse<TypeWithCondition<T>>){console.log(b);};functiontest1<T>(a: TypeWithCondition<T>){if(a===false)thrownewError("Can't be false");logNonFalse(a);// Error : Argument of type 'true | ([T] extends ["1"] ? "1" : never)' is not assignable to parameter of type 'true'.// Type '[T] extends ["1"] ? "1" : never' is not assignable to type 'true'.// Type '"1"' is not assignable to type 'true'.(2345)};
Output
"use strict";functionlogNonFalse(b){console.log(b);};functiontest1(a){if(a===false)thrownewError("Can't be false");logNonFalse(a);// Error : Argument of type 'true | ([T] extends ["1"] ? "1" : never)' is not assignable to parameter of type 'true'.// Type '[T] extends ["1"] ? "1" : never' is not assignable to type 'true'.// Type '"1"' is not assignable to type 'true'.(2345)};
TypeScript Version: 3.9.2
Search Terms:
Expected behavior: No error, Typescript should guess that a variable of type
T extends '1' ? '1' : never
will never befalse
, so thatNonFalse<TypeWithCondition<T>>
is exactly the same thantrue | (T extends '1' ? '1' : never)
Actual behavior: Error on
logNonFalse(a);
Related Issues: none
Code
Output
Compiler Options
Playground Link: Provided
The text was updated successfully, but these errors were encountered: