From a901b7a5ad111939e54c66f8875314ad51e9b4ac Mon Sep 17 00:00:00 2001 From: zhongsp Date: Thu, 14 Feb 2019 16:26:13 +0800 Subject: [PATCH] Add code samples: use class expression to implements construct signature. PR742 --- doc/handbook/Interfaces.md | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/doc/handbook/Interfaces.md b/doc/handbook/Interfaces.md index 8397493..5c2e0b0 100644 --- a/doc/handbook/Interfaces.md +++ b/doc/handbook/Interfaces.md @@ -413,6 +413,25 @@ let analog = createClock(AnalogClock, 7, 32); 因为`createClock`的第一个参数是`ClockConstructor`类型,在`createClock(AnalogClock, 7, 32)`里,会检查`AnalogClock`是否符合构造函数签名。 +另一种简单方式是使用类表达式: + +```ts +interface ClockConstructor { + new (hour: number, minute: number); +} + +interface ClockInterface { + tick(); +} + +const Clock: ClockConstructor = class Clock implements ClockInterface { + constructor(h: number, m: number) {} + tick() { + console.log("beep beep"); + } +} +``` + # 继承接口 和类一样,接口也可以相互继承。