备注: 单独的 index.d.ts对于代码实现没有约束性,将约束和实现写在一个页面里有约束性,或者使用如下:
// clock.interface.ts
export interface ClockInterface {
currentTime: Date;
setTime(d: number): number;
}
// clock.ts
import { ClockInterface } from './clock.interface'
class Clock implements ClockInterface {
currentTime: Date;
constructor(h: number, m: number) {
this.currentTime = new Date();
}
setTime(time: number) {
return new Date(time).getTime();
}
}