Skip to content

Don’t allow an object literal with a spread as a fallback for destructuring a property not present in all constituents #43783

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

Merged
merged 2 commits into from
Apr 23, 2021

Conversation

andrewbranch
Copy link
Member

Fixes #43174

#31711 allowed object literals as fallbacks for destructuring, such that const { x } = foo || {} was allowed even though {} has no property x. The only criteria for an object constituent of a union to be considered to have { [key: string]: undefined } index signature was that it be an object literal—the common pattern seems to be an empty object literal, but any object literal ought to avoid excess property pitfalls through aliasing.... except, that logic neglected spreads, which could introduce arbitrary extra properties of arbitrary types, as demonstrated in #43174.

@andrewbranch andrewbranch added the Breaking Change Would introduce errors in existing code label Apr 22, 2021
@andrewbranch
Copy link
Member Author

@typescript-bot user test this
@typescript-bot test this

@typescript-bot typescript-bot added Author: Team For Milestone Bug PRs that fix a bug with a specific milestone labels Apr 22, 2021
@typescript-bot
Copy link
Collaborator

typescript-bot commented Apr 22, 2021

Heya @andrewbranch, I've started to run the parallelized community code test suite on this PR at 2950db9. You can monitor the build here.

@typescript-bot
Copy link
Collaborator

typescript-bot commented Apr 22, 2021

Heya @andrewbranch, I've started to run the extended test suite on this PR at 2950db9. You can monitor the build here.

@typescript-bot
Copy link
Collaborator

The user suite test run you requested has finished and failed. I've opened a PR with the baseline diff from master.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Author: Team Breaking Change Would introduce errors in existing code For Milestone Bug PRs that fix a bug with a specific milestone
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Immediately destructuring a spread union allows access to properties not present in all union constituents
4 participants