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

Object.assign return assigned type instead merged #28553

Closed
wants to merge 1 commit into from
Closed

Object.assign return assigned type instead merged #28553

wants to merge 1 commit into from

Conversation

anion155
Copy link

Got 'assing' in my eyes. Found some old bugs created in 16 (#11100). So I made this quick PR.

Situation:

let a = {
  a: 'string',
  b: { c: 4 },
};
let b = {
  a: 5,
  b: { d: 3 },
}
Object.assign({ }, a, b);

Result of this operation is { a: 5, b: { d: 3 } }, but TS says its of { a: string & number; b: { c: number; d: number; } } type, which is obviously wrong (according to mozilla's JS reference).

@sandersn
Copy link
Member

We actually decided recently to double down on this incorrect definition of spread and Object.assign in #28234. In practise, the most common use of spread is to spread two identical types. The second most common use is to spread two disjoint types. Spreading two overlapping types is pretty rare, so we decided not to create a type operator for it.

Also note that Assign is still not correct, since it doesn't understand own properties, optional properties, or private properties. getSpreadType handles these aspects, but doesn't work for higher-order cases since we didn't create the spread type operator.

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

Successfully merging this pull request may close these issues.

2 participants