💎一站式轻松地调用各大LLM模型接口,支持GPT4、智谱、星火、月之暗面及文生图 广告
>[success] # Extract -- 联合类型交集 ~~~ 1.联合类型交集指定交集 ~~~ >[danger] ##### 源码 ~~~ type Extract<T, U> = T extends U ? T : never; ~~~ >[danger] ##### 案例 ~~~ type Type11 = Extract<'a' | 'b' | 'c', 'c' | 'b'|'f'> // type Type11 = "b" | "c" 取两者的交集 ~~~ >[danger] ##### 扩展获取接口交集 ~~~ type Intersect<T, U> = { [K in Extract<keyof T, keyof U>]: T[K]; }; interface Person { name: string; age?: number; weight?: number; } interface NewPerson { name: string; age?: number; } type T = Intersect<Person, NewPerson>; // 相当于 type T = { name: string; age?: number; }; ~~~