[英]Can I define a specific class type in a class that implements an interface with a generic type in typescript?
[英]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.