Readit News logoReadit News
mock-possum · 2 years ago
I wish there was more exhaustive explanations for some of these -

> Enums : Prefer object const assertion over enum.

But I like enums!

kkirsche · 2 years ago
https://blog.logrocket.com/why-typescript-enums-suck/ may be a good introduction. I love enums in other languages but they can come with some unexpected behaviors in typescript
mock-possum · 2 years ago
It’s a good introduction but it’s review in my case - I know how enums work in TS.

But the end conclusion

> Enums in TypeScript are a very useful addition to the JavaScript language when used properly.

> They can help make it clear the intent of normally “magic values” (strings or numbers) that may exist in an application and give a type-safe view of them.

> But like any tool in one’s toolbox, if they are used incorrectly, it can become unclear what they represent and how they should be used.

Doesn’t really support the original post’s premise that prefers not to use enums.

marko424 · 2 years ago
> I love enums in other languages

This. Also huge on enums elsewhere, just not in typescript. I think this could be the reason devs first reach out to enums, since familiarity from other languages.

marko424 · 2 years ago
In general nothing wrong with enums, but imo you need to be a bit more careful when utilising them.

Deleted Comment