Skip to content

Spreading array to object not typing correctly #54207

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
tcK1 opened this issue May 10, 2023 · 2 comments
Closed

Spreading array to object not typing correctly #54207

tcK1 opened this issue May 10, 2023 · 2 comments

Comments

@tcK1
Copy link

tcK1 commented May 10, 2023

Bug Report

🔎 Search Terms

Spread, Spreading, Array, Object, Destruct, Destructuring

🕗 Version & Regression Information

  • This is the behavior in every version I tried, and I reviewed the FAQ for entries about Spreading an array to an Object.

⏯ Playground Link

Playground Link

💻 Code

const a = [1, 2, 3];
const b = { ...a };
b.pop();

🙁 Actual behavior

TS did not show that .pop() did not exist in the new variable. The new variable type has "all the properties" from the array, including the prototype functions. I guess that's why it failed to show that the function doesn't exist.

Example of the code failing:

🙂 Expected behavior

It should show values from the Object prototype and not from Array.

@MartinJohns
Copy link
Contributor

Duplicate of #52060 / #9726.

@tcK1
Copy link
Author

tcK1 commented May 10, 2023

Thanks, @MartinJohns!

@tcK1 tcK1 closed this as completed May 10, 2023
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

2 participants