-
Notifications
You must be signed in to change notification settings - Fork 13k
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
type Person = { name: string; } ^ { firstname: string; lastname: string; };
const p1: Person = { name: "Foo" };
const p2: Person = { firstname: "Foo", lastname: "Bar" } ;
const bad1: Person = { name: "Foo", lastname: "Bar" }
~~~~~~~~~~~~~~~ Type Person can not have name and firstname together
const bad2: Person = { lastname: "Bar", name: "Foo" }
~~~~~~~~~~~ Type Person can not have lastname and name together
For literal and primitive types it should behave like union type:
// These are the same
type stringOrNumber = string | number;
type stringORNumber = string ^ number;
battmanz, rylphs, KonanMentor, Vaelor, lukescott and 127 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