Skip to content

Spread operator on function call won't work if the spreaded parameter is not the last #39206

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

Closed
avshyz opened this issue Jun 23, 2020 · 3 comments

Comments

@avshyz
Copy link

avshyz commented Jun 23, 2020

TypeScript Version: 3.9.2

Search Terms: spread, rest operator, function call

Code

function foo(x: number, y: number, z: number, f: number, aleph: number) { }
function baz(x: number, y: number, z: number) { }

const args: [number, number, number] = [0, 1, 2];

baz(...args);        // working
foo(3, 1, ...args);  // working
foo(1, ...args, 2);  // COMPILER ERROR - Expected 5 arguments, but got 2 or more.(2556)
foo(...args, 3, 2);  // COMPILER ERROR - Expected 5 arguments, but got 2 or more.(2556)

Expected behavior: given every one of these lines works in js (see mdn), one could expect them to work. Especially given the first two lines worked

Actual behavior: The following compilation error

Expected 5 arguments, but got 2 or more.(2556)
input.ts(1, 36): An argument for 'z' was not provided.

Playground Link: here

Related Issues: I actually posted it as a comment here but thought it might deserve an independent bug report

@dragomirtitian
Copy link
Contributor

This actually works on 4.0 Playground Link

This is probably due to #39094

@avshyz
Copy link
Author

avshyz commented Jun 23, 2020

Oh shame, you're right!
I thought 3.9.2 is the latest version, as it's the latest one shown in the playground.

Thanks for the quick reply

@avshyz avshyz closed this as completed Jun 23, 2020
@MartinJohns
Copy link
Contributor

I thought 3.9.2 is the latest version, as it's the latest one shown in the playground.

@avshyz 3.9.2 is currently the latest version. TypeScript 4.0 has not yet been released (currently scheduled for August 2020), but it's available in the playground as a "nightly" version.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants