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

Name collisions in intersection types should be of a union type #19102

Closed
attatrol opened this issue Oct 11, 2017 · 2 comments
Closed

Name collisions in intersection types should be of a union type #19102

attatrol opened this issue Oct 11, 2017 · 2 comments
Labels
Duplicate An existing issue was already created

Comments

@attatrol
Copy link

attatrol commented Oct 11, 2017

TypeScript Version: 2.4.0 / nightly (2.5.0-dev.201xxxxx)

Code

const x = Object.assign({}, {type: '42'}, { type: 42 });
let type = x.type;
type.substring(0); // runtime failure

Expected behavior:
Variable type should be number | string.
Actual behavior:
It is number & string.

In general we cannot presume that every function that produces intersections will also intersect any properties.

@mhegazy
Copy link
Contributor

mhegazy commented Oct 11, 2017

The use of intersection in Object.assign is an approximation. the correct behavior is that of spread, i.e. the type for the property in the last argument overrides those of the previous argument. that is tracked by #11100.
We first need higher-order spread operator to be added to the language, which is tracked by #10727

@mhegazy mhegazy added the Duplicate An existing issue was already created label Oct 11, 2017
@mhegazy
Copy link
Contributor

mhegazy commented Oct 25, 2017

Automatically closing this issue for housekeeping purposes. The issue labels indicate that it is unactionable at the moment or has already been addressed.

@mhegazy mhegazy closed this as completed Oct 25, 2017
@microsoft microsoft locked and limited conversation to collaborators Jun 14, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Duplicate An existing issue was already created
Projects
None yet
Development

No branches or pull requests

2 participants