Skip to content

Omit should distribute over union typesΒ #47263

Closed
@askvortsov1

Description

@askvortsov1

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions