TypeScript 0.9重载是可调用的
我有下面这个问题的例子。在TypeScript 0.9中,我似乎能够调用重载方法的最终签名:TypeScript 0.9重载是可调用的,typescript,Typescript,我有下面这个问题的例子。在TypeScript 0.9中,我似乎能够调用重载方法的最终签名: class Test { method(...names: string[]) : void; method(names: string[]) : void { } } var x= new Test(); x.method('One', 'Two', 'Three'); x.method(['One', 'Two', 'Three']); 在TypeScript 0.8
class Test {
method(...names: string[]) : void;
method(names: string[]) : void {
}
}
var x= new Test();
x.method('One', 'Two', 'Three');
x.method(['One', 'Two', 'Three']);
在TypeScript 0.8.x中,必须指定第三个签名,因此:
class Test {
method(...names: string[]) : void;
method(names: string[]) : void;
method(names: any) : void {
}
}
var x= new Test();
x.method('One', 'Two', 'Three');
x.method(['One', 'Two', 'Three']);
最后的签名不应该隐藏吗?(因为它最有可能包含具有
任何类型等的过度泛化签名)。0.8.x行为是正确的;我们在0.9中有一个回归,现在在developer分支中得到了修正。实现签名确实永远不可见。什么是最终签名?最终签名是具有实现的签名(即,不是以;
结尾的签名)。在最后一个例子中,最后一个签名是方法(名称:any):void{
,其余的都是重载签名。