I'd like to have a type that says:
If there's property container present, also expect property a. If there's item property present, also expect property b. container and item cannot exist both at the same time.
The code I'd assume would look as follows, but it doesn't seem to do the above.
type A = { container: true; a: string } | { item: true; b: number };
How do I build such a type?
null | string seems to mean null OR string, but SomeObject | AnotherObject seems to mean all properties present BOTH in SomeObject and AnotherObject.
containeroritem, but not both and not none. Then, add a conditional type that, depending on which property is present, intersects the resulting type with either{ a:string }or{ b: number }. You could also use a discriminated union, but this definition lacks a discriminant property