I need a type in which some optional properties depend on each other.
I.e. if an object defines one such property, then it must define all other properties that depend on it.
I thought of separating the main type and the sets of optional properties, and then having a union type, but it doesn't seem to work.
Namely, I expect that if
interface T {a: any, b: any}
interface U {c: any, d, any}
type V = T | (T & U)
Then v: V
would only be able to contain either {a, b}
or {a, b, c, d}
.
However, typescript shows no error when v
only has {a, b, c}
(which is neither T
, nor T & U
).
What am I missing?
Also, could there be a more succint way of expressing T | (T & U)
?