工作根据打字稿documentation(寻找字符串文字类型部分),下面的代码应该打字稿工作:打字稿字符串文字类型没有函数重载
function createElement(tagName: "img"): HTMLImageElement;
function createElement(tagName: "input"): HTMLInputElement;
// ... more overloads ...
function createElement(tagName: string): Element {
// ... code goes here ...
}
当我运行代码,或一些更有意义的变化,对TypeScript Playground,或在Visual Studio中,我得到以下错误:
Specialized overload signature is not assignable to any non-specialized signature.
什么建议吗?在尝试在自己的代码上实现非常类似的东西后,我遇到了这个错误。
它的工作原理,谢谢!大! 你有任何解释为什么它的工作?我试图理解。 – FrancoSF
不确定,也许是因为专门的签名无法看到它们之后的实现?更多细节[here](http://stackoverflow.com/a/32212966/3478605)。 –