接口

接口标识符

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())
posted @ 2022-01-03 16:49  最爱宋人头  阅读(36)  评论(0编辑  收藏  举报