---
title: "Discussion on \"In Defence of Typescript Enums\" | Hashnode"
description: "Discussion on \"In Defence of Typescript Enums\". You're (Probably) Using Them Wrong"
url: "https://hashnode.com/posts/in-defence-of-typescript-enums/67eae66767c03ec6e67a8760"
---

[Feed](https://hashnode.com/feed) /

Discussion

# [In Defence of Typescript Enums](https://yazanalaboudi.dev/in-defence-of-typescript-enums?utm_source=hashnode&utm_medium=feed)

You're (Probably) Using Them Wrong

Mar 31, 2025 · 6 min read · yazanalaboudi.dev  
Read the article

-   [#typescript](https://hashnode.com/tag/typescript)
-   [#enum](https://hashnode.com/tag/enum)
-   [#antipattern](https://hashnode.com/tag/antipattern)

## Written by

[Yazan Alaboudi](https://hashnode.com/@alaboudi)

@alaboudi

  
[View profile](https://hashnode.com/@alaboudi)

Software Engineer

## Responses 4

Markdown supported · ⌘↵ to post

[renkinjutsushi](https://hashnode.com/@renkinjutsushi)

[Apr 10, 2025](https://hashnode.com/posts/in-defence-of-typescript-enums/67eae66767c03ec6e67a8760/comment/67f7a175703a4870e57dcaac)

What if the UI would send 'Go' to the API but the instruction would need to be translated into the enum value? In this case it would be 2.

Would we use a reverse map for the instructions?

i.e.

"const fromInstructions = new Map(\[ \["Stop", TrafficLight.Red\], \["Slow down", TrafficLight.Yellow\], \["Go", TrafficLight.Green\], \]);"

Or do you reckon it would be ok keeping them in the same instructions map?

[Yazan Alaboudi](https://hashnode.com/@alaboudi)

[Apr 10, 2025](https://hashnode.com/posts/in-defence-of-typescript-enums/67eae66767c03ec6e67a8760/comment/67f7a175703a4870e57dcaac#reply-67f7c08522540a9bd8a5c418)

I typically create a map when translating my enum to an API value. And another map when translating from API value to an enum. Each map would basically have a single responsibility.

This all makes sense as serialization and de-serialization are different responsibilities. So you'd have a map for each.

[Anıl Anar](https://hashnode.com/@anilanar)

[Apr 3, 2025](https://hashnode.com/posts/in-defence-of-typescript-enums/67eae66767c03ec6e67a8760/comment/67eeef36454d36c3f4067d7e)

People use string literal enums because numeric enums are completely backwards. Arbitrary numbers can be assigned to enums types, even when they are out of range. So numeric enum type is nothing more than just a `number`. Did something change since then?

[Anıl Anar](https://hashnode.com/@anilanar)

[Apr 4, 2025](https://hashnode.com/posts/in-defence-of-typescript-enums/67eae66767c03ec6e67a8760/comment/67eeef36454d36c3f4067d7e#reply-67efcfd53086d4b203ad73ed)

[Yazan Alaboudi](https://hashnode.com/@alaboudi)

Here's the issue that plagues only numeric enums, and not string enums:

```
enum Animal {
  Lion,
  Tiger,
}

const justANumber: number = 5;

// No type error
const myAnimal: Animal = justANumber;
```

Typescript made this historical error at some point and never tried to remedy it, let's say, by introducing a config such as `strictNumericEnums: boolean`.

[Yazan Alaboudi](https://hashnode.com/@alaboudi)

[Apr 4, 2025](https://hashnode.com/posts/in-defence-of-typescript-enums/67eae66767c03ec6e67a8760/comment/67eeef36454d36c3f4067d7e#reply-67f01bb2561cf1b6c1e52049)

[Anıl Anar](https://hashnode.com/@anilanar) This is no longer an issue with the latest version of Typescript. It's been addressed.

[Anıl Anar](https://hashnode.com/@anilanar)

[Apr 4, 2025](https://hashnode.com/posts/in-defence-of-typescript-enums/67eae66767c03ec6e67a8760/comment/67eeef36454d36c3f4067d7e#reply-67f06158b166cbf815606e2e)

[Yazan Alaboudi](https://hashnode.com/@alaboudi)

Which version of Typescript?

[typescriptlang.org/play](https://www.typescriptlang.org/play/?ts=5.9.0-dev.20250404#code/PTAEDsFcFsFMCcCWBjUsrQFDpqAguItAIYA2oA3pqKADKID24ANNaACqIDmCrAvpkzImAZwAuoAFaRxeAHIwARggBcEJQlABeUAFYA3IJCg5DUGICeAB1hp48BvCGiJ0CwSJk1HkuR3TZBWhleEMjMHEkcC40DGwMfEJfACZKNhp6Jm1QAHJSRnAc1hoaTh54bJyxbgQczAFncHEpGTE8AGUxKK41SMRo7IAiADMGBkVieEGw43ZrWwQHeABCRua3HzJk7ySt7IC2zu79IA)

[Drew Hoover](https://hashnode.com/@drewhoo)

[Apr 1, 2025](https://hashnode.com/posts/in-defence-of-typescript-enums/67eae66767c03ec6e67a8760/comment/67ebeab568031b1d889ba130)

When I read this title, I was ready to come out swinging against enums since, as you point out, they're nearly never used in a way that gives them an advantage over, say, string literal unions. But you've described their use case really well!

[xs217](https://hashnode.com/@xs217)

[Apr 1, 2025](https://hashnode.com/posts/in-defence-of-typescript-enums/67eae66767c03ec6e67a8760/comment/67eb489d7c13b16e6640277f)

Wait.. are people actually complaining about these things? You're correct about its intended use, I'd be heavily offended if someone actually spewed "const obj = {} is better" because that's apples and oranges, enums aren't meant to store lookup values. Enum exists to create type-correctness attached to a name rather than a value. They're designed to reduce human error on arbitrary values. It's best to think of an enum's values as being capable of changing every time the application restarts (even though in reality they don't unless the body of the enum is changed).

[Yazan Alaboudi](https://hashnode.com/@alaboudi)

[Apr 1, 2025](https://hashnode.com/posts/in-defence-of-typescript-enums/67eae66767c03ec6e67a8760/comment/67eb489d7c13b16e6640277f#reply-67eb617606cbc895f8701295)

You'd be surprised to see the messages I'm responding to on other platforms
