接口的继承
interface Animal {
eat(): void;
}
interface Person extends Animal {
work(): void;
}
class Web implements Person {
public name: string;
constructor(name: string) {
this.name = name;
}
eat() {
console.log(this.name + "喜欢吃馒头");
}
work() {
console.log(this.name + "写代码");
}
}
接口和类搭配使用
interface Animal {
eat(): void;
}
interface Person extends Animal {
work(): void;
}
class Programmer {
public name: string;
constructor(name: string) {
this.name = name;
}
coding(code: string) {
console.log(this.name + code);
}
}
class Web extends Programmer implements Person {
constructor(name: string) {
super(name);
}
eat() {
console.log(this.name + "喜欢吃馒头");
}
work() {
console.log(this.name + "写代码");
}
}
var w = new Web("小李");
w.coding("写ts代码");