【发布时间】:2016-04-21 21:03:12
【问题描述】:
根据 TypeScript documentation(查找 String Literal Types 部分),以下代码应该适用于 TypeScript:
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.
有什么建议吗?在尝试在我自己的代码上实现非常相似的东西后,我遇到了这个错误。
【问题讨论】: