Hacker News new | past | comments | ask | show | jobs | submit login

The proper analog to union types in Dart (as in Java) is enums and / or church-encoding [I think that's the term] generalized algebraic data types (GADTs). E. g. something like this: https://gist.github.com/jbgi/208a1733f15cdcf78eb5

Scala 2 also had `sealed` classes that could be used in places where you needed enums parameterized by runtime values and that's been generalized in Scala 3 IIRC.




I'm certainly confused now whether or not we are talking about the same thing. Without delving to much on the use of the word "union", how would you solve the use case presented in the typescript examples using enums?


Reading more about it, it could seem that we are talking about the same thing, except that it was so far over my head, that I didn't realise it.




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: