Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

I wish there was more exhaustive explanations for some of these -

> Enums : Prefer object const assertion over enum.

But I like enums!



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


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.


> 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.


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




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: