I wrote a short example to explain the situation occurred to my code.
I have two functions resembles to following:
function sum3(a: number, b: number, c: number): number {
return a + b + c
}
function plus1(...args: number[]): number[] {
return args.map(x => x + 1)
}
function sum3, the first one, needs exact 3 number arguments. e.g. sum3(1, 2, 3) returns 6.
function plus, the second one, has no limit on the number of arguments. e.g. plus1(100, 200) returns Array of number [101, 201], plus1(300, 400, 500) returns [301, 401, 501].
The error happened when I tried to call the function sum3 with spread syntax.
// javascript returns 303
// typescript throws an error: Expected 3 arguments, but got 1 or more. (TS2556)
sum3(101, ...plus1(100, 100))
My typescript version is the newest, 4.2.4. Is this a bug?
...isn't an operator, operators can't do what...does.