Why isn't this code functioning properly?
Could it be a case where Typescript overlooks that a variable of type (T extends '1' ? '1' : never)
will never be false
, making
NonFalse<TypeWithCondition<T>>
exactly the same as true | (T extends '1' ? '1' : never)
?
Is this an issue with Typescript? Should it be brought up as a Feature Request?
type TypeWithCondition<T> = boolean | (T extends '1' ? '1' : never);
type NonFalse<T> = Exclude<T, false>;
const logNonFalse = <T>(b: NonFalse<TypeWithCondition<T>>) => {
console.log(b);
};
const test1 = <T>(a: TypeWithCondition<T>) => {
if (a === false) throw new Error("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)
};