Is that type a conditional types?

48 Views Asked by At
type TestType<T> = T extends string ? 1: 2
let demo: testType<string | number>; // => 1 | 2

type T1 = (string extends string ? 1 : 2)  | ( number extends string ? 1 : 2)// => 1 | 2
type T2 = (string | number) extends string ? 1 : 2 // => 2 why?

TestType is conditional types, and it is similar T1 ,but what is the different with T2?

0

There are 0 best solutions below