- Partial<Type>
- Readonly<Type>
- Pick<Type, Keys>
- Record<Keys, Type>
Partial<Type>
用来构造 (创建) 一个类型, 将 Type 的所有属性设置为可选
interface Props{
id:string
children:number[]
}
type PartialProps=Partial<Props>
Readonly<Type>
用来构造一个类型, 将 Type 的所有属性都设置为 readonly (只读 )
interface Props{
id:string
children:number[]
}
type ReadonlyProps=Readonly<Props>
构造出来的结构完全相同,但所有属性为只读
Pick<Type, Keys>
从 Type 中选择一组属性来构造新类型
interface Props{
id:string
children:number[]
}
type PickProps=Pick<Props,'id'>
//想当于又声明了 一个{id:string}类型
Record<Keys,Type>
构造一个对象类型,属性键为 Keys ,属性类型为 Type。
type Recordtype = Record<'id'|'name',string>
//想当于
interface Recordtype{
id:string
name:string
}