6 ms·
Show HN: TypeScript Style Guide
- mock-possum 3y agoI wish there was more exhaustive explanations for some of these - > Enums : Prefer object const assertion over enum. But I like enums!
- deleted 3y ago[deleted]
- kkirsche 3y agohttps://blog.logrocket.com/why-typescript-enums-suck/ 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
- marko424 3y 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.
- mock-possum 3y agoIt’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 3y agoIn general nothing wrong with enums, but imo you need to be a bit more careful when utilising them.