TS的内置类型 Omit Pick
Omit 是从对象中排出一些属性,得到对象类型
// 排除单个
type OmitPerson = Omit<Person, 'age'>
// 排除多个
type OmitPerson = Omit<Person, 'age' | 'gender'>
Pick 是从对象中摘取一些属性,得到对象类型
// 摘取单个
type PickPerson = Pick<Person, 'gender'>
// 摘取多个
type PickPerson = Pick<Person, 'gender' | 'name'>
// Omit Pick TS的内置类型
type Person = {
name: string
age: number
gender: 0 | 1
}
type OmitPerson = Omit<Person, 'age' | 'gender'>
type PickPerson = Pick<Person, 'gender' | 'name'>