Re:From Rust to TypeScript
by eyelidlessness on Saturday September 12, 2020 @12:46PM
(#24453685)
I don’t understand why so many people advise against TS enums. The string variant is no different at runtime from a const of the same mapping, but they also achieve nominal typing in an otherwise structural type system, which is super useful for preventing ambiguity errors
[ Parent
| on HN ]
I've done TypeScript for 5-6 years, in up to 100+k loc codebases, and never had a problem with enums, both with tsc and babel (so yeah, `const enum` no worky).
`Object.values(SomeEnum)` is pretty handy, something you can't do with string union types.