ts接口扩展、接口继承

接口扩展:接口可以继承接口

interface Animal{
	eat():void;
}
interface Person extends Animal{
	work():void;
}
class Web implements Person{
	name: string
	constructor(name:string){
		this.name = name
	}
	eat () {
		console.log(`${this.name}喜欢吃馒头`)
	}
	work(){
		console.log(`${this.name}写代码`)
	}
}

var w = new Web('ruby')
w.eat()
w.work()
interface Animal{
	name:string;
	eat(val:string):void;
}
interface Person extends Animal{
	work():void;
}
class Programmer{
	name:string
	constructor(name:string){
		this.name = name
	}
	coding(code:string):void{
		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('Aric')
w.work()
w.eat()
w.coding('js css')

你可能感兴趣的:(TypeScript)