Take a look at this defined type:
type MyType =
| { a: number }
| { b: number }
| { c: number }
| ({ b: number } & { c: number });
The goal is to prevent the combination of 'a' with either 'b' or 'c'.
const o1: MyType = { a: 10 }; // only 'a': OK
const o2: MyType = { b: 10 }; // only 'b': OK
const o3: MyType = { c: 10 }; // only 'c': OK
const o4: MyType = { b: 10, c: 10 }; // combine 'b' and 'c': OK
// const o5: MyType = {}; // Forbidded (no fields)
const o6: MyType = { a: 10, b: 10 }; // Forbidden ('a' and 'b' should not be combinable)
I'm confused because TypeScript allows me to create object 'o6'. Ideally, combining 'a' and 'b' should not be allowed...
Any thoughts or suggestions?
Thank you