Skip to content

Omit should distribute over union types #47263

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

Closed
askvortsov1 opened this issue Dec 29, 2021 · 3 comments
Closed

Omit should distribute over union types #47263

askvortsov1 opened this issue Dec 29, 2021 · 3 comments

Comments

@askvortsov1
Copy link

askvortsov1 commented Dec 29, 2021

Bug Report

πŸ”Ž Search Terms

omit union

πŸ•— Version & Regression Information

  • This is the behavior in every version I tried since 3.5 where Omit was introduced, and I reviewed the FAQ for entries about omit

⏯ Playground Link

Playground Link

πŸ’» Code

type A = {
    shared: string;

    something: true;

    exclusiveToA: string;
}

type B = {
    shared: string;

    something: false;

    exclusiveToB: string;
}

type C = A | B;

type D = Omit<C, 'shared'>;

const a: D = {
    something: true,
    exclusiveToA: 'here',
}

const b: D = {
    something: false,
    exclusiveToB: 'here',
}

πŸ™ Actual behavior

Omit strips away properties of its union type operands that don't have common keys

πŸ™‚ Expected behavior

Omit should recursively distribute over union/product type expressions

@MartinJohns
Copy link
Contributor

Duplicate of #46361. Used search terms: omit union (same as you)

@askvortsov1
Copy link
Author

Duplicate of #46361. Used search terms: omit union (same as you)

Huh, not sure how I missed that... Thanks!

@MartinJohns
Copy link
Contributor

Probably just looked at the open issues? :-D If you add in:title you will find a lot more duplicates, with less noise.

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

No branches or pull requests

2 participants