Hacker News new | past | comments | ask | show | jobs | submit
I personally see TS enums as an anti-pattern.

One big reason: you can't name it interfaces.d.ts, or import as type, which has widespread implications:

Your types are now affecting your shipped bundles.

Sure that's a small bit of size - but it can actually lead to things like server side code getting shipped to the client.

Whereas if it's all .d.ts stuff you know there's no risk of chained dependencies.

I'd go so far as to say default eslint rules should disallow enums.

I’ve also seen them behave very weirdly and inconsistently. There have been cases when I’ve had to explicitly declare that a value has an enum type, even though its type is already one of the enum’s values (and not a literal of the same value, but literally straight from the enum itself).

From what I can tell, they were an early addition from back before TS had unions, and it feels like they live in their own world within the type system. I would go further than saying you should disallow them with a linter, and say that they should be deprecated in the language. Right now they’re just a foot gun for new TS devs.