Skip to content

Using Omit weakens type checkingΒ #46361

Closed
@Bastian

Description

@Bastian

Bug Report

When using the Omit type, the type-checking does not catch some cases that it previously did.

πŸ”Ž Search Terms

Omit inaccurate

πŸ•— Version & Regression Information

Test in both 3.3.3 and 4.5.0-beta.

⏯ Playground Link

Playground link with relevant code

πŸ’» Code

interface A {
  type: "a";
  payload: string;
  something: string;
}

interface B {
  type: "b";
  payload: boolean;
  something: string;
}

type AB = A | B;

type ABwithoutSomething = Omit<AB, "something">;

const a1: ABwithoutSomething = {
  type: "a",
  payload: true, // This should not work, but it does (unexpected)
};

const a2: AB = {
  type: "a",
  payload: true, // Without the Omit, the compiler complains here (expected)
  something: "",
};

πŸ™ Actual behavior

When using the Omit type to exclude a single field, the type checking is weaker.

πŸ™‚ Expected behavior

When using Omit, the only difference should be that the field is excluded without any other side-effects or weaker typechecks.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Working as IntendedThe behavior described is the intended behavior; this is not a bug

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions