Aaron Powell
Mar 17, 2020 ⋅ 5 min read

Why TypeScript enums suck

Aaron Powell I’m a Developer Advocate at Microsoft. My area of specialty is frontend web development focusing on architecture around SPA and other UI-heavy web applications.

Recent posts:

Decoupling Monoliths Into Microservices With Feature Flags

Decoupling monoliths into microservices with feature flags

Explore how to effectively break down a monolithic application into microservices using feature flags and Flagsmith.

Kayode Adeniyi
Jul 25, 2024 ⋅ 10 min read
Lots of multi-colored blue and purplish rectangles.

Animating dialog and popover elements with CSS @starting-style

Native dialog and popover elements have their own well-defined roles in modern-day frontend web development. Dialog elements are known to […]

Rahul Chhodde
Jul 24, 2024 ⋅ 10 min read
Using Llama Index To Add Personal Data To Large Language Models

Using LlamaIndex to add personal data to LLMs

LlamaIndex provides tools for ingesting, processing, and implementing complex query workflows that combine data access with LLM prompting.

Ukeje Goodness
Jul 23, 2024 ⋅ 5 min read
JavaScript logo on top of violet background

Exploring essential DOM methods for frontend development

Learn four groups of DOM methods and their uses to create responsive and dynamic webpages. A helpful DOM reference table is also included.

Chimezie Innocent
Jul 23, 2024 ⋅ 12 min read
View all posts

2 Replies to "Why TypeScript enums suck"

  1. I’d prefer them over enums every single time. They cover all the regular cases for enums, and the ones they don’t cover, there you shouldn’t use enums either. I’m talking about doing math with enums.
    Wether it’s bit-flags or stuff like `if(day < DaysOfWeek.Saturday)…`.

    Additionally they are nice and readable when I have to deal with JSON or a Database. When I'm greeted by the day "Monday", "Tuesday", "Wednesday" instead of 1,2,3.

    And if someone now thinks, counting down the days of the week is trivial, tell me: what's the first value in your enum? 1? Or did you start at 0 so that the values double as indices over an array of localized strings? And what is the first Entry? Sunday or Monday? You wrote Sunday, in my area that's the last day of the week. And all that just with something as "trivial" as days of week. Now imagine a somewhat more abstract collection of options and you tell me which numeric value translates to what readable option in that enum.

Leave a Reply