Skip to content

Spread operator function arguments (regression) #28794

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
sheley1998 opened this issue Dec 1, 2018 · 3 comments
Closed

Spread operator function arguments (regression) #28794

sheley1998 opened this issue Dec 1, 2018 · 3 comments
Labels
Working as Intended The behavior described is the intended behavior; this is not a bug

Comments

@sheley1998
Copy link

TypeScript Version: 3.2.1

Search Terms: spread, arguments

Code

function test(a: number, b: number, c: number, d: number) {
    console.log(a, b, c, d);
}

const nums = [0, 1, 2, 3];

test(...nums);

Expected behavior:
the snippet above should compile without error

Actual behavior:
Error TS2556: Expected 4 arguments, but got 0 or more

@ahejlsberg
Copy link
Member

This is working as intended and is not a regression. We infer type number[] for nums and therefore we have to assume that the array may have as few as zero elements. It would be nice to infer a tuple type, but the reality is that arrays are mutable (the only thing that is const in the example is the array reference--the contents of the array are not). There are many similar issues already logged, e.g. #28336, #20899, #16389, #3369.

@ahejlsberg ahejlsberg added the Working as Intended The behavior described is the intended behavior; this is not a bug label Dec 1, 2018
@sheley1998
Copy link
Author

Thank you for the clarification :)

@typescript-bot
Copy link
Collaborator

This issue has been marked 'Working as Intended' and has seen no recent activity. It has been automatically closed for house-keeping purposes.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Working as Intended The behavior described is the intended behavior; this is not a bug
Projects
None yet
Development

No branches or pull requests

3 participants