// interface 接口
interface Person {
readonly id: number; //只读属性 不能再赋值
name: string;
age?: number; // ?可选属性
}
let user: Person = {
id: 1,
name: 'leu',
age: 20,
}
//-------------//----------------
interface Radio {
switchRadio(): void;
}
interface Battery {
ceheckBatterStatus(): void;
}
//接口继承
interface RadioWidthBattery extends Radio {
ceheckBatterStatus(): void;
}
class Car implements Radio {//创建类
switchRadio() {
}
}
// class Cellphone implements Radio, Battery {
// switchRadio() {
//
// }
// ceheckBatterStatus() {
//
// }
// }
//接口继承合并
class Cellphone implements RadioWidthBattery {
switchRadio() {
}
ceheckBatterStatus() {
}
}
6.类和接口
最新推荐文章于 2021-07-27 11:49:53 发布