一、高级类型
- class
- 类型兼容性
- 交叉类型
- 泛型和keyof
- 索引签名类型和索引查询类型
- 映射类型
二、class
- 构造函数给变量赋值
- extends 继承
implement 实现接口
// 感叹号表示虽然没有初始化,但一定会有值
class Person {
name!: string
gender = '男'
}
let p = new Person()
p.name = '小乔'
p.gender = '女'
console.log(p)
class Person {
name: string
gender: string
age: number
constructor(name: string, gender: string, age: number) {
this.name = name
this.age = age
this.gender = gender
}
setName: (name: string) => void = (name) => {
this.name = name
}
setAge(age: number) {
this.age = age
}
}
let p = new Person('大乔', '女', 18)
标签:TypeScript,string,gender,age,高级,Person,类型,class,name
From: https://www.cnblogs.com/his365/p/16822395.html