Open mohsen1 opened 4 years ago
I'm curious to hear your perspective on this because you have a lot of experience with advanced generics
Just curious, how is this any different from using the basic or '|'? I know the difference between or and xor, but I don't see how this example would benefit from an XOR option.
Edit: I played around with the example some more and now typescript bothers me.
type NameOnly = { name: string };
type FirstAndLastName = {firstname: string; lastname: string };
type Person =NameOnly | FirstAndLastName;
const person: Person = {firstname: 'john', lastname: 'doe', name: 'micheal'}
This should be valid TS How is this in anyway what you would expect? Saying it is type A or B and than a weird mix of both is allowed!
XOR is really useful type. Built-in union type allows a mix of two types, which is unwanted behavior.
Is your feature request related to a real problem or use-case?
This is from a long discussion in TS issues
https://github.com/microsoft/TypeScript/issues/14094?fbclid=IwAR05mMCDTNFE1xEB1dAbsfsqgDn5QS5ufDoYf1xyJJ8qdx7jStmHHn_KK0Q#issuecomment-373782604
Describe a solution including usage in code example
Who does this impact? Who is this for?
A lot of APIs that return one or another responses.