繁体   English   中英

如何定义“实现”接口的类型?

[英]How can I define a type that “implements” an interface?

类可以实现接口:

interface ClockInterface {
    currentTime: Date;
}

class Clock implements ClockInterface {
    currentTime: Date;
    constructor(h: number, m: number) { }
}

如何定义“实现”接口的类型? 我不明白以下原因为何不起作用,因为在我看来,这完全合理:

type DigitalClock implements ClockInterface = {
    currentTime: Date;
    somethingDigital: any;
}

只需使用

type DigitalClock = ClockInterface & {
    somethingDigital: any;
}

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM