Skip to content

Destructuring into an empty object vs an object with existing properties yields different results #60386

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

Open
rivatove opened this issue Oct 31, 2024 · 2 comments Β· May be fixed by #61641
Open
Labels
Bug A bug in TypeScript Help Wanted You can do this
Milestone

Comments

@rivatove
Copy link

πŸ”Ž Search Terms

"destructuring", "record"

πŸ•— Version & Regression Information

  • This is the behavior in every version I tried, and I reviewed the FAQ.

⏯ Playground Link

https://www.typescriptlang.org/play/?ts=5.6.3#code/MYewdgzgLgBATgU1HAJgdQJZQBYGUpwZgDmEAXDAEpIioA80hJANDI0cQHwwC8MA3gF8A3AChRCAB4AHWrFCRYiZOizYAcgFcAtgCMEcclRr12LGGB3643Pv1EwYUggEMACnBDSDUAJ4UABmYHGAA6cOVaVRx8JlJgkSA

πŸ’» Code

This raises a type error:

const recordWithStrings: Record<string, string> = {};

export const recordWithNumbers: Record<string, number> = {
  ...recordWithStrings,
};

and this doesn't:

const recordWithStrings: Record<string, string> = {};

export const recordWithNumbers: Record<string, number> = {
  extraProperty: 0,
  ...recordWithStrings,
};

Is there a sound reason for that?

πŸ™ Actual behavior

The 2nd example doesn't raise a type error.

πŸ™‚ Expected behavior

The 2nd example should raise a type error.

Additional information about the issue

No response

@jcalz

This comment has been minimized.

@RyanCavanaugh RyanCavanaugh added Bug A bug in TypeScript Help Wanted You can do this labels Oct 31, 2024
@RyanCavanaugh RyanCavanaugh added this to the Backlog milestone Oct 31, 2024
@Andarist
Copy link
Contributor

The reported code is almost an exact copy of what was reported in this comment #27273 (comment) and here #56431 . The last experiment to fix this was worked on here #56441

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug A bug in TypeScript Help Wanted You can do this
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants