I have a type that is structured like so:
type MyType = {
a: string;
b: string;
c?: number;
d?: string;
}
Instances of this type can take different forms such as:
const myObj1: MyType = { a, b };
const myObj2: MyType = { a, b, c, d };
If an object of type MyType
includes property c
, then it must also include property d
. Is there a way to define this type without needing non-null assertion or checking for both types, other than extending the type into a separate one?