An Ode to TypeScript Enums

This page summarizes the projects mentioned and recommended in the original post on news.ycombinator.com

InfluxDB high-performance time series database
Collect, organize, and act on massive volumes of high-resolution data to power real-time intelligent systems.
influxdata.com
featured
CodeRabbit: AI Code Reviews for Developers
Revolutionize your code reviews with AI. CodeRabbit offers PR summaries, code walkthroughs, 1-click suggestions, and AST-based analysis. Boost productivity and code quality across all major languages with each PR.
coderabbit.ai
featured
  1. TypeScript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

    > Obviously, this approach is even more inconvenient at the implementation side, but I find it more convenient on the consumer side. The implementer side complexity is less relevant if using codegen. `Symbol` is also skipped in `JSON.stringify` for both keys and values, so if you rely on it then it won't work and you'd need a branded primitive type if you care about nominal typing. I use schema-guided serialization so it's not an issue for me, but it's worth mentioning.

    > Both the `as const` approach and my "class symbols" approach addresses [the complaints in this blog post about support variant annotations such `@deprecated`](https://blog.disintegrator.dev/posts/ode-to-typescript-enums...)). My class symbols approach gives you the flexibility to have different annotations for values and types; but I'm not sure how relevant it is. (It can also be achieved with `as const`, what matters for this is the type namespace declaration).

    > I hope this message helps others when evaluating available solutions when migrating away from TS `enum`s.

    [0]: https://github.com/microsoft/TypeScript/pull/61011#issuecomm...

  2. InfluxDB

    InfluxDB high-performance time series database. Collect, organize, and act on massive volumes of high-resolution data to power real-time intelligent systems.

    InfluxDB logo
  3. proposal-enum

    Proposal for ECMAScript enums

    Given the TypeScript team's stance on new non-erasable syntax, I have to think this is how they would have gone if they had `as const` from the beginning. Ron Buckton of the TS team is championing an enum proposal for JS: https://github.com/rbuckton/proposal-enum Hopefully that goes somewhere and improves the declaration side of thigns too.

  4. purescript

    A strongly-typed language that compiles to JavaScript

    When I see this it makes me want to run for ReasonML/ReScript/Elm/PureScript.

    Sum types (without payloads on the instances they are effectively enums) should not require a evening filling ceremonial dance event to define.

    https://reasonml.github.io/

    https://rescript-lang.org/

    https://elm-lang.org/

    https://www.purescript.org/

    (any I forgot?)

    It's nice that TS is a strict super set of JS... But that's about the only reason TS is nice. Apart from that the "being a strict super set" hampers TS is a million and one ways.

    To my JS is too broken to fix with a strict super set.

  5. rescript

    ReScript is a robustly typed language that compiles to efficient and human-readable JavaScript.

    When I see this it makes me want to run for ReasonML/ReScript/Elm/PureScript.

    Sum types (without payloads on the instances they are effectively enums) should not require a evening filling ceremonial dance event to define.

    https://reasonml.github.io/

    https://rescript-lang.org/

    https://elm-lang.org/

    https://www.purescript.org/

    (any I forgot?)

    It's nice that TS is a strict super set of JS... But that's about the only reason TS is nice. Apart from that the "being a strict super set" hampers TS is a million and one ways.

    To my JS is too broken to fix with a strict super set.

  6. reason

    Simple, fast & type safe code that leverages the JavaScript & OCaml ecosystems

    When I see this it makes me want to run for ReasonML/ReScript/Elm/PureScript.

    Sum types (without payloads on the instances they are effectively enums) should not require a evening filling ceremonial dance event to define.

    https://reasonml.github.io/

    https://rescript-lang.org/

    https://elm-lang.org/

    https://www.purescript.org/

    (any I forgot?)

    It's nice that TS is a strict super set of JS... But that's about the only reason TS is nice. Apart from that the "being a strict super set" hampers TS is a million and one ways.

    To my JS is too broken to fix with a strict super set.

  7. Elm

    Compiler for Elm, a functional language for reliable webapps.

    When I see this it makes me want to run for ReasonML/ReScript/Elm/PureScript.

    Sum types (without payloads on the instances they are effectively enums) should not require a evening filling ceremonial dance event to define.

    https://reasonml.github.io/

    https://rescript-lang.org/

    https://elm-lang.org/

    https://www.purescript.org/

    (any I forgot?)

    It's nice that TS is a strict super set of JS... But that's about the only reason TS is nice. Apart from that the "being a strict super set" hampers TS is a million and one ways.

    To my JS is too broken to fix with a strict super set.

  8. Civet

    A TypeScript superset that favors more types and less typing

    Civet (https://civet.dev) is probably my favorite one if I want something a bit fancier than Typescript, purely because it shares the same elements that you are as "opt-in" as much as you like, at least in my limited experience.

  9. CodeRabbit

    CodeRabbit: AI Code Reviews for Developers. Revolutionize your code reviews with AI. CodeRabbit offers PR summaries, code walkthroughs, 1-click suggestions, and AST-based analysis. Boost productivity and code quality across all major languages with each PR.

    CodeRabbit logo
NOTE: The number of mentions on this list indicates mentions on common posts plus user suggested alternatives. Hence, a higher number means a more popular project.

Suggest a related project

Related posts

  • Show HN: Zero-codegen TypeScript type inference from Protobuf messages

    5 projects | news.ycombinator.com | 14 Apr 2025
  • Building React Components Using Unions in TypeScript

    15 projects | dev.to | 1 Oct 2023
  • Type inference of local variable based on later operations

    3 projects | /r/ProgrammingLanguages | 10 Jun 2023
  • Announcing TypeScript 5.0

    3 projects | /r/programming | 16 Mar 2023
  • TypeScript Enum's vs Discriminated Unions

    3 projects | dev.to | 12 Dec 2022

Did you know that Haskell is
the 25th most popular programming language
based on number of references?