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:

Radix Ui Adoption Guide Overview Examples And Alternatives

Radix UI adoption guide: Overview, examples, and alternatives

Radix UI is quickly rising in popularity and has become an excellent go-to solution for building modern design systems and websites.

Nefe Emadamerho-Atori
Apr 25, 2024 ⋅ 11 min read
Understanding The Css Revert Layer Keyword, Part Of Css Cascade Layers

Understanding the CSS revert-layer keyword

In this article, we’ll explore CSS cascade layers — and, specifically, the revert-layer keyword — to help you refine your styling strategy.

Chimezie Innocent
Apr 24, 2024 ⋅ 6 min read
Exploring Nushell, A Rust Powered, Cross Platform Shell

Exploring Nushell, a Rust-powered, cross-platform shell

Nushell is a modern, performant, extensible shell built with Rust. Explore its pros, cons, and how to install and get started with it.

Oduah Chigozie
Apr 23, 2024 ⋅ 6 min read
Exploring Zed, A Newly Open Source Code Editor Written In Rust

Exploring Zed, an open source code editor written in Rust

The Zed code editor sets itself apart with its lightning-fast performance and cutting-edge collaborative features.

Nefe Emadamerho-Atori
Apr 22, 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