Appearance
Omit
与 Pick 相反的 从一个复合类型中剔除对应类型后返回的复合类型
ts
// 其实现也是通过 Exclude 去获取复合类型中除了K外的其他Key
type Omit<T, K extends keyof any> = Pick<T, Exclude<keyof T, K>>
栗子
ts
const person = {
name: "张三",
age: 12,
address: "南京",
}
type Person = typeof person
type PersonKeys = keyof Person
// 就剩下 address
type MiniPerson = Omit<typeof person, "name" | "age"> // { "address": string;}
// {}
type OmitMiniPerson1 = Omit<typeof person, "name" | "age" | "address">