Skip to content

Incorrect type when spreading two Sets to an object #47999

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
styfle opened this issue Feb 22, 2022 · 2 comments
Closed

Incorrect type when spreading two Sets to an object #47999

styfle opened this issue Feb 22, 2022 · 2 comments

Comments

@styfle
Copy link
Contributor

styfle commented Feb 22, 2022

Bug Report

I had a typo where I used curly brackets instead of square brackets to spread to Set variables, but TypeScript didn't catch the error at build time. Instead, the code failed at runtime.

🔎 Search Terms

set, object, spread

🕗 Version & Regression Information

  • This is the behavior in every version I tried back to TS 3.x

⏯ Playground Link

Playground link with relevant code

💻 Code

const first = new Set(['one'])
const second = new Set(['two'])
const all = { ...first, ...second };
console.log(all) // prints `{}`
all.add('wat') // TS is happy but JS throws a runtime error

🙁 Actual behavior

TS thinks the Set methods like .add() and .clear() are available and doesn't show a build error for the last line.

🙂 Expected behavior

TS should show an error at build time to reflect actual JS usage at runtime: no Set method are available for the last line.

@nmain
Copy link

nmain commented Feb 22, 2022

I believe this is a duplicate of #9726

@styfle
Copy link
Contributor Author

styfle commented Feb 22, 2022

Yep, looks like a very similar to #33081 which is a duplicate of #9726

@styfle styfle closed this as completed Feb 22, 2022
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