【发布时间】:2019-07-04 11:17:56
【问题描述】:
通常我可以掌握打字稿语言的大部分功能,但有时函数重载仍然相当具有挑战性。
我无法理解为什么 typescript 编译器不断在以下代码 (mcve) 上抛出 error TS2394: Overload signature is not compatible with function implementation:
class Editor {
replace(
searchValue: { [Symbol.match](string: string): RegExpMatchArray; },
replaceValue: string,
): this;
replace(
searchValue: { [Symbol.match](string: string): RegExpMatchArray; },
replacer: (substring: string, ...args: any[]) => string,
): this {
return this;
}
}
唯一的区别在于第二个参数:string 或 (substring: string, ...args: any[]) => string。
为什么编译器不能将它们组合成string | (substring: string, ...args: any[]) => string?
【问题讨论】:
标签: typescript typescript-types