在 http://www.typescriptlang.org/Handbook#interfaces网站上解释了混合类型.因为这些对于创建JS的输入非常有用 – 我想知道是否可以定义一个实现例如JS的类.这样的界面: interface Counter { (start:
interface Counter {
(start: number): string;
interval: number;
reset(): void;
}
如果没有,那么可能只创建该类型的对象?怎么样?
I wonder if it’s possible to define a class implementing
没有
If not then maybe it’s possible to create just an object of that type?
是.将使用类型断言(或任何):
interface Counter {
(start: number): string;
interval: number;
reset(): void;
}
function getCounter():Counter{
var counter = <Counter>function(start:number){};
counter.interval = 123;
counter.reset = function(){};
return counter;
}
