備註: 單獨的 index.d.ts對於代碼實現沒有約束性,將約束和實現寫在一個頁面裏有約束性,或者使用以下:this
// 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(); } }