Hacker News new | ask | show | jobs
by pierreyoda 1888 days ago
> Hmm, what did I miss, why do people hate them exactly?

In my experience, enums are far less type safe and convenient (usage in switch for instance, combined with a linter) than union types.

1 comments

The thing is enum and union type have different use cases. Union type cannot be used to check against incoming data. It's a lightweight type level feature. There is no way for compiler to identify the unknown data object from the network. Enum is essentially an object in memory which can be used in this case.