Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Using Typescript spread operator results in compile error

Using VS17RC with TS 2.1

function foo(x:number, y:number, z:number) { console.log(x + y + z)}
var args = [0, 1, 2];
foo(...args);

gives the compile time error "Supplied parameters do not match any signature of call target."

This is the compiled js:

function foo(x, y, z) { console.log(x + y + z); }
var args = [0, 1, 2];
foo.apply(void 0, args);

which does in fact work.

Is there something I am doing wrong here?

The example comes from here: Typescript Deep Dive

like image 407
Greg Gum Avatar asked Aug 25 '26 16:08

Greg Gum


1 Answers

There's an open issue on the exact same example:
Compiler incorrectly reports parameter/call target signature mismatch when using the spread operator

The issue is marked as bug, but it's there from Aug 3, 2015, and has no set milestone.

like image 86
Nitzan Tomer Avatar answered Aug 27 '26 10:08

Nitzan Tomer



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!