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

TS thinks spreading Map into object still has Map properties #53765

Closed
elramus opened this issue Apr 13, 2023 · 2 comments
Closed

TS thinks spreading Map into object still has Map properties #53765

elramus opened this issue Apr 13, 2023 · 2 comments
Labels
Duplicate An existing issue was already created

Comments

@elramus
Copy link

elramus commented Apr 13, 2023

Bug Report

🔎 Search Terms

Map
Spread

🕗 Version & Regression Information

Not sure when it started, testing on current version. Same behavior observed in Nightly.

  • This is the behavior in every version I tried, and I reviewed the FAQ for entries about Maps.

⏯ Playground Link

Playground link

💻 Code

const myMap = new Map([
  ['foo', 'bar']
])

// TS thinks this is a Map, but it's not.
const myNewMap = { ...myMap }

// myNewMap.get is not a function 
myNewMap.get('foo') 

🙁 Actual behavior

TypeScript thinks get will be present, along with all the other Map properties. Running the code crashes though, because spreading the Map into the object yields an object.

🙂 Expected behavior

I'm not sure if TS mistakenly thinks the new object is a Map, or if is mistakenly grabbing the properties of the Map class, but one way or another it seems like TS should know that that spreading a Map into an object means no more Map properties.

@RyanCavanaugh
Copy link
Member

Duplicate #53747, etc

@RyanCavanaugh RyanCavanaugh added the Duplicate An existing issue was already created label Apr 13, 2023
@elramus
Copy link
Author

elramus commented Apr 13, 2023

@RyanCavanaugh thanks

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

2 participants