我有以下问题示例。在 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.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']);

不应该隐藏最终签名吗? (因为它很可能包含具有 any 类型等的过度概括的签名)。

最佳答案

0.8.x 行为是正确的;我们在 0.9 中有一个回归,现在在开发分支中修复了。实现签名确实永远不可见。

关于TypeScript 0.9 重载是可调用的,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/17054539/

10-12 12:19
查看更多