/**
* Exclude from T those types that are assignable to U
*/
type Exclude<T, U> = T extends U ? never : T;
/**
* Extract from T those types that are assignable to U
*/
type Extract<T, U> = T extends U ? T : never;
做个测试
因为a是a b c 的子集所以P是never,这个好理解
O居然返回的是10,按照语义,T extends U ? never : T
T不是U的子集,那么返回的就应该是T,也就是a 10 ,但是推断出来的是a,这个怎么解释?
这跟 typescript 2.8引入的有条件类型里的所谓裸类型有关,细节你可以看这个 conditional-types,这个是个简单的描述 Typescript: what is a “naked type parameter”