Closed
Description
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.