0

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;
}
user1283776
  • 19,640
  • 49
  • 136
  • 276
  • 2
    That type is simply the interface. You can extend interfaces from other interfaces. – jo_va Feb 26 '19 at 11:01
  • Possible duplicate of [What is the "type" reserved word in TypeScript?](https://stackoverflow.com/questions/31364693/what-is-the-type-reserved-word-in-typescript) – Igor Feb 26 '19 at 11:15

1 Answers1

2

Just use

type DigitalClock = ClockInterface & {
    somethingDigital: any;
}
Nguyen Phong Thien
  • 3,237
  • 1
  • 15
  • 36