Supposed I have two interface, X
and Y
, that both share a few fields, but have independent fields as well:
interface X {
abc: number;
foo: number;
bar: number;
}
interface Y {
abc: number;
foo: number;
baz: number;
}
Now I create a union of those types:
type Z = X | Y;
The resulting type is either X or Y
, which is fine. Now I remove one of the common fields using Omit
:
type limitedZ = Omit<Z, 'foo'>;
What I'd expect is that limitedZ
has the following form:
{ abc: number, bar: number } | { abc: number, baz: number }
Instead, the independent fields are gone and all that is left is the abc
field which is shared by both. Why is that?
here is a demo link