type Foo = {
a: string
b: number
c: boolean
}
type A = MyOmit<Foo, 'a' | 'b'> // {c: boolean}
type B = MyOmit<Foo, 'c'> // {a: string, b: number}
type C = MyOmit<Foo, 'c' | 'd'> // {a: string, b: number}
答题
// your code here, please don't use Omit<T, K> in your code
type MyOmit<T, K extends keyof any> = {
//Exclude操作联合类型
[key in Exclude<keyof T, K>]: T[key]
}
implement Omit<T, K>
omit<T,K>在T中过滤K,并返回过滤后的新类型
Exclude只能操作联合类型,即:type union= 'a' | 'b' | 'c'