Classes can implement interfaces:
interface ClockInterface {
currentTime: Date;
}
class Clock implements ClockInterface {
currentTime: Date;
constructor(h: number, m: number) { }
}
How can I define a type that "implements" an interface? I don't understand why the following does not work, as it looks completely reasonable to me:
type DigitalClock implements ClockInterface = {
currentTime: Date;
somethingDigital: any;
}
Just use
type DigitalClock = ClockInterface & {
somethingDigital: any;
}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.