interface 接口
interface IPerson {
readonly id: number // 只读属性
firstName: string // 必传属性
lastName: string
age?: number // 可选属性
talk: () => void
run: string | string[] | (() => string) // 联合类型
[propName: string]: any // 任意属性
}
const person: IPerson = {
id: 1,
firstName: '屁虫',
lastName: '放',
run: '我会跑步',
talk() {
console.log(`我的名字是${this.lastName}${this.firstName}`)
},
dance() {
console.log('我会跳舞')
}
}
person.talk()类实现接口
接口继承接口
接口继承类
Last updated