I am trying to make a props type for a React component that can have certain fields but can also have additionally two more fields. But they have to be both specified, or not specifed at all.
I was trying to achieve this with the following example:
interface Base {
f: string;
d: string;
}
interface ExtendedBase extends Base {
a: string;
b: string;
}
const obj: Base | ExtendedBase = { // shouldn't this give an error that 'b' is missing?
f: '',
d: '',
a: ''
}
I thought that with union it will require 2 Base fields or 4 ExtendedBase fields, but in the example above specifiying only 3 fields seems to satisfy the union, but why?
Any thoughts? Much appreciated.