2020-03-17
1611
#typescript
Aaron Powell
15368
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:

Building a Full-Featured Laravel Admin Dashboard with Filament

Building a full-featured Laravel admin dashboard with Filament

Build scalable admin dashboards with Filament and Laravel using Form Builder, Notifications, and Actions for clean, interactive panels.

Kayode Adeniyi
Dec 20, 2024 ⋅ 5 min read
Working With URLs In JavaScript

Working with URLs in JavaScript

Break down the parts of a URL and explore APIs for working with them in JavaScript, parsing them, building query strings, checking their validity, etc.

Joe Attardi
Dec 19, 2024 ⋅ 6 min read
Lazy Loading Vs. Eager Loading

Lazy loading vs. Eager loading

In this guide, explore lazy loading and error loading as two techniques for fetching data in React apps.

Njong Emy
Dec 18, 2024 ⋅ 5 min read
Deno logo over an orange background

How to migrate your Node.js app to Deno 2.0

Deno is a popular JavaScript runtime, and it recently launched version 2.0 with several new features, bug fixes, and improvements […]

Yashodhan Joshi
Dec 17, 2024 ⋅ 7 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