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

union type {x, y} | {x, z} sometimes incorrectly allows {x, y, z} #43691

Closed
felix9 opened this issue Apr 15, 2021 · 3 comments
Closed

union type {x, y} | {x, z} sometimes incorrectly allows {x, y, z} #43691

felix9 opened this issue Apr 15, 2021 · 3 comments
Labels
Duplicate An existing issue was already created

Comments

@felix9
Copy link

felix9 commented Apr 15, 2021

Bug Report

πŸ”Ž Search Terms

union type

πŸ•— Version & Regression Information

  • This is the behavior in every version I tried, and I reviewed the FAQ for entries about union types

⏯ Playground Link

Playground link with relevant code

πŸ’» Code

type XY<T> = {
    x: T;
    y: T;
};
type XZ<U> = {
    x: U;
    z: U;
};

// This is correctly an error
const a: XY<boolean> | XZ<string> = { x: true, y: true, z: 'z' };

// This is incorrectly allowed
const b: XY<number> | XZ<string> = { x: 1, y: 1, z: 'z' };
@DanielRosenwasser
Copy link
Member

I think this is a duplicate of #20863.

@andrewbranch andrewbranch added the Duplicate An existing issue was already created label Apr 15, 2021
@felix9
Copy link
Author

felix9 commented Apr 16, 2021

It's similar? but I'm not sure I understand why it behaves differently when I change the type from number to boolean.

this irregularity makes me completely confused about union types, I don't feel like I can predict at all what will and won't work.

@typescript-bot
Copy link
Collaborator

This issue has been marked as a 'Duplicate' and has seen no recent activity. It has been automatically closed for house-keeping purposes.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Duplicate An existing issue was already created
Projects
None yet
Development

No branches or pull requests

4 participants