在 TS 2.1 中使用 VS17RC
function foo(x:number, y:number, z:number) { console.log(x + y + z)}
var args = [0, 1, 2];
foo(...args);
给出编译时错误“提供的参数与调用目标的任何签名都不匹配。”
这是编译后的js:
function foo(x, y, z) { console.log(x + y + z); }
var args = [0, 1, 2];
foo.apply(void 0, args);
这确实有效。
我这里有什么地方做错了吗?
例子来自这里:Typescript Deep Dive
最佳答案
在完全相同的示例上有一个 Unresolved 问题:
Compiler incorrectly reports parameter/call target signature mismatch when using the spread operator
问题被标记为 bug
,但它从 2015 年 8 月 3 日开始存在,并且没有设定里程碑。
关于typescript - 使用 Typescript 展开运算符导致编译错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41147103/