Based on this comment TypeScript does not allow exclusive union types.
I'm proposing a logical or operator similar to union (|) or intersection (&) operators that allows defining types that are one or another.
Code
typePerson={name: string;}^{firstname: string; lastname: string;};constp1: Person={name: "Foo"};constp2: Person={firstname: "Foo",lastname: "Bar"};constbad1: Person={name: "Foo",lastname: "Bar"}~~~~~~~~~~~~~~~TypePersoncannothavenameandfirstnametogetherconstbad2: Person={lastname: "Bar",name: "Foo"}~~~~~~~~~~~TypePersoncannothavelastnameandnametogetherFor literal and primitive types it should behave like union type:
// These are the same typestringOrNumber=string|number;typestringORNumber=string^ number;
Based on this comment TypeScript does not allow exclusive union types.
I'm proposing a logical or operator similar to union (
|) or intersection (&) operators that allows defining types that are one or another.Code
For literal and primitive types it should behave like union type: