Skip to content
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

Wrong type infer for spread arrays #31809

Closed
worudso opened this issue Jun 7, 2019 · 6 comments
Closed

Wrong type infer for spread arrays #31809

worudso opened this issue Jun 7, 2019 · 6 comments
Labels
Duplicate An existing issue was already created

Comments

@worudso
Copy link

worudso commented Jun 7, 2019

TypeScript Version: 3.6.0-dev.20190606

Search Terms:
spread, array
Code

const a = {
  ...[1, 2, 3],
};
a.slice // === undefined actually!
console.log(a.slice);

Expected behavior:
a doesn't have slice property
Actual behavior:
a has slice property for Array type.
Playground Link:
https://www.typescriptlang.org/play/#src=const%20a%20%3D%20%7B%0D%0A%20%20...%5B1%2C%202%2C%203%5D%2C%0D%0A%7D%3B%0D%0Aa.slice%20%2F%2F%20%3D%3D%3D%20undefined%20actually!%0D%0Aconsole.log(a.slice)%3B
Related Issues:

@fatcerberus
Copy link

...wait, is that even a legal thing to do? Spreading an array into an object like that?

@worudso
Copy link
Author

worudso commented Jun 7, 2019

It works. In that case, you got { 0: 1, 1: 2, 2: 3 } for a.
I know it's not recommended even possible, but I found a special use case for it. #31575 (comment)

@fatcerberus
Copy link

Yeah, arrays are just objects like almost everything else in JS, of course that would work. Brainfart on my part, ignore my stupidity. 😄

@AnyhowStep
Copy link
Contributor

#28801

@RyanCavanaugh RyanCavanaugh added the Duplicate An existing issue was already created label Jun 17, 2019
@RyanCavanaugh
Copy link
Member

#9726

@typescript-bot
Copy link
Collaborator

This issue has been marked as a 'Duplicate' 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
Duplicate An existing issue was already created
Projects
None yet
Development

No branches or pull requests

5 participants