交叉类型及联合类型
interface Bird {
name: string,
fly(): void
}
interface Person {
age: number,
talk(): void;
}
type BirdMan = Bird & Person;
let chaoren: BirdMan = {
name: 'lee',
fly() {},
age: 1,
talk(){}
}
对象转类型【typeof】
let people = {
name: "北鸟南游",
age: 18
}
// 将people对象直接转化为type类型People
type People = typeof people;
限制类型属性【keyof】
type Animal = {
kinds:string;
name: string;
legs: number;
}
// 获取type类型别名的key值
type AnimalKey = keyof Animal; // 'kinds'|'name'|'legs'
映射类型【keyof+in】
type Person = {
name: string,
age: number,
gender: boolean
}
//PersonMap是从Person映射的类型,该类型各属性都变为可选
type PersonMap = {
[key in keyof Person]?: Person[key]
}
let p1:PersonMap = {name: '北鸟南游'};
内置类型
Partial
Required
Readonly
Pick
内置条件类型
Exclude
Extract
NonNullable
ReturnType
InstanceType