- Notifications
You must be signed in to change notification settings - Fork 13.2k
Closed
Labels
DeclinedThe issue was declined as something which matches the TypeScript visionThe issue was declined as something which matches the TypeScript visionSuggestionAn idea for TypeScriptAn idea for TypeScript
Description
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;battmanz, rylphs, KonanMentor, Vaelor, lukescott and 128 more
Metadata
Metadata
Assignees
Labels
DeclinedThe issue was declined as something which matches the TypeScript visionThe issue was declined as something which matches the TypeScript visionSuggestionAn idea for TypeScriptAn idea for TypeScript