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

{ tag: 'foo' | 'bar' } should be assignable to { tag: 'foo' } | { tag: 'bar' } #19813

Closed
pelotom opened this issue Nov 7, 2017 · 1 comment
Closed
Labels
Duplicate An existing issue was already created

Comments

@pelotom
Copy link

pelotom commented Nov 7, 2017

Logically it seems like this should work:

declare const x: { tag: 'foo' | 'bar' };

const foobar: { tag: 'foo' } | { tag: 'bar' } = x
//    ^^^^^^ Type '{ tag: "foo" | "bar"; }' is not assignable to type '{ tag: "foo"; } | { tag: "bar"; }'.
//             Type '{ tag: "foo" | "bar"; }' is not assignable to type '{ tag: "bar"; }'.
//               Types of property 'tag' are incompatible.
//                 Type '"foo" | "bar"' is not assignable to type '"bar"'.
//                   Type '"foo"' is not assignable to type '"bar"'.

Of course this is only the case if there aren't additional fields with differing types for tag to discriminate, so this is admittedly perhaps a niche use case.

@mhegazy
Copy link
Contributor

mhegazy commented Nov 7, 2017

Duplicate of #14865

@mhegazy mhegazy marked this as a duplicate of #14865 Nov 7, 2017
@mhegazy mhegazy added the Duplicate An existing issue was already created label Nov 7, 2017
@pelotom pelotom closed this as completed Nov 7, 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