其他分享
首页 > 其他分享> > 接口

接口

作者:互联网

接口标识符

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())

标签:Swim,log,void,接口,interface,swimming
来源: https://www.cnblogs.com/xiaoqi11/p/15759877.html