我尝试使用手册“Difference between static/instance side of class”部分下的技巧来指定类的静态方(即函数)的接口:
export interface StaticInterface {
info: string;
}
class _X {
static info = 'something';
...
}
export var X: StaticInterface = _X;
但是当我在另一个文件中尝试extend theModule.X
时,编译器说:
error TS2305: Module '"..."' has no exported member 'X'.
答案 0 :(得分:2)
以下是基于TypeScript手册的工作示例:
module Example {
export interface ClockStatic {
new (hour: number, minute: number);
}
class Clock {
currentTime: Date;
constructor(h: number, m: number) { }
}
export var cs: ClockStatic = Clock;
}
var newClock = new Example.cs(7, 30);
导出接口非常重要,并且该类正确实现了接口。