-
Notifications
You must be signed in to change notification settings - Fork 12.8k
spread operator as arguments and optionals + REST in function parameters throws error #11780
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
Your program has an error, it is calling The correct way to call foo(undefined, ...args);
console.log(undefined, ...args); |
Yeah, I understand that don't match the signature, but ts checker may merge arguments if you use spreading function x(...args: number[]);
function x(a: number, ...args: number[]) {}
x(...[1, 2, 3]); //ok //this is not correct
console.log(undefined, ...args);
// correct code
console.log(args[0], ...args.slice(1)); |
I've got a bit similar issue, basically, spread arguments do not translate to multiple arguments.
Pretty annoying, as in pure ES6 it works perfectly :(. |
I had the same issue when trying to wrap console.log().
for reference console.log is defined as
So my code is correct from the type point of view. |
How is that a question? Perfectly valid ES6 code throws an error in TypeScript. That's a bug, no a feature. |
your correct, relabeling. the issue is tracked by #5296 |
👍 |
TypeScript Version: 2.0.3
Code
The text was updated successfully, but these errors were encountered: