接口
接口标识符
interface Swim {
swimming: () => void
}
//作为标识符
const a: Swim = {
swimming() {
return 'sss'
}
}
console.log(a);
类实现接口
interface Swim {
swimming: () => void
}
interface Run {
running: () => void
}
//类来实现接口
//继承只能单继承
//实现: 实现接口,类可以实现多个接口
class Person implements Swim{
swimming(){
console.log('人游泳');
}
}
function someAction(value:Swim){
value.swimming()
}
someAction(new Person())