文章写的很乱第一次写,因为看了一些文章,发现解释是错误的,按照错误的解释,使用了好多次,怎么编译都报错,所以自己尝试理解了一下,做出总结,不求有多少赞同! Exclude: 源码: type Exclude<T, U> = T extends U ? never : T; 解释:U 里面类型有继承自T的吗?有:(返回类型清空,即没有任何类型never),没有继承自T的返回T的类型 interface T { str: string, s: number, bol: boolean, k: boolean, ll:string } /* interface U{ l:string } */ /interface U{ ll:string }/
type y = Exclude<T, U> let fs: y = { str: 'string', s: 1, bol: false, k: false, ll:'' } 分别打开注释的地方,发现验证解释 type M = Exclude<1 | 2 | 3 | 4 | 5, 3 | 4> let num: M = 1