Comment by mostlylurks

3 years ago

> What's wrong with enums?

They don't compile down to just the same code with the type annotations and definitions removed, which is often considered to be the ideal that typescript should follow. Instead, they compile down to some more complicated blob of javascript. People critique and avoid typescript's namespaces for the same reason.

> Enum types in general are very useful.

You can use unions for the same purpose without the aforementioned drawback, and unions have other benefits which typescript's enums don't offer, like support for more complex data types, which makes unions closer to set of features more modern languages tend to offer via enums, while making enums closer to the barebones enums found in languages like C and C++ (effectively just a set of named constants enclosed into a type).

I guess I don't value the "TS transpiles to JS 1-to-1" property very much.

Unions are useful for quite a few things. But I literally was talking about the barebones (and thus simple to write) C/C++ style enums. Where I know it can be one of several primitive values and not have to spend the time creating a class for each possible value.