例如
type A = {
name: string
age?: number
sex?: number
}
type B = FilterOptional<A> // => { name: string }
把所有可选的属性过滤掉,这个FilterOptional
应该怎么写
例如
type A = {
name: string
age?: number
sex?: number
}
type B = FilterOptional<A> // => { name: string }
把所有可选的属性过滤掉,这个FilterOptional
应该怎么写
type FilterOptional<T extends object> = Pick<T, Exclude<{
[K in keyof T]: T extends Record<K, T[K]>
? K
: never
}[keyof T], undefined>>;