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

Disjoint enums and spread operator - false incompatibility #3126

Closed
wbecker opened this issue Jan 3, 2017 · 4 comments
Closed

Disjoint enums and spread operator - false incompatibility #3126

wbecker opened this issue Jan 3, 2017 · 4 comments

Comments

@wbecker
Copy link

wbecker commented Jan 3, 2017

Here is an example.

type Combined = | "AA" | false;

const x: Combined = "AA"; // ok
const y: Combined = false;  // ok

type OO = {foo?: Combined};

const o1: OO = {foo: "AA"}; // ok
const o2: OO = {foo: false}; // ok
o1.foo = o2.foo; // ok

const o3 = {foo: false, ...o1}; //error: This type is incompatible with boolean
const o4 = {foo: "AA", ...o1}; //error: This type is incompatible with boolean
const o5 = {...o1, ...o2}; // ok

In this case, the disjoint enum works fine on individual variables, and fine when assigned normally to an object.

However, when using the spread operator it can't figure out how to combine them, but only if you have explicitly set a value (o3 & o4). If you combine two objects using the spread operator without explicitly adding the value, it does work (o5)

@wbecker
Copy link
Author

wbecker commented Jan 3, 2017

This may be a duplicate of #1488

@wbecker
Copy link
Author

wbecker commented Jan 3, 2017

As suggested by o5, this does work however:

const o3 = {...{foo: false}, ...o1};
const o4 = {...{foo: "AA"}, ...o1};

@villesau
Copy link
Contributor

This fixes the issue: #7298

@nmote
Copy link
Contributor

nmote commented Oct 25, 2019

This no longer errors in master

@nmote nmote closed this as completed Oct 25, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants