Re:TypeScript enums: use cases and alternatives
by zarzavat on Tuesday January 21, 2025 @02:12AM
(#42777362)
enums are a feature of most programming languages. It doesn't matter to me why TypeScript had to add them, just like it doesn't matter why JS has functions or if statements.
90% of the enums I use are regular integer enums. I don't get much use out of string enums, as you say union types do that job just fine.
In the vast majority of cases, there's no good reason to do that.
Edit: But no, the reason enums in TypeScript suck is not that JS doesn't have them. That wouldn't fix anything other than the type stripping problem. The main reason that they suck is that they use a completely different type model from the rest of the language.