top | item 40368717

(no title)

stiiv | 1 year ago

It depends on what you're trying to achieve. If there are sufficient structural differences, you're fine (`"foo" in myThing` can discrimate) but if two types in your union have the same structure, TS doesn't give you a way to tell them apart. (This relates back to branded types.)

A good example would be `type Money = Dollars | Euros` where both types in the union alias `number`. You need a tag. In other languages, you don't.

discuss

order

anamexis|1 year ago

True, although I think that's just missing branded types, not discriminated unions.