TypeScript enums: use cases and alternatives

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

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
SaaSHub - Software Alternatives and Reviews
SaaSHub helps you find the best software and product alternatives
www.saashub.com
featured
  1. TypeScript

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

    > Enums is going to make your TypeScript code not work in a future where TypeScript code can be run with Node.js

    Apparently they're planning on adding a tsconfig option to disallow these Node-incompatible features as well [1].

    Using this limited subset of TS also allows your code to compile with Bloomberg's ts-blank-space, which literally just replaces type declarations with blank spaces [2].

    [1] https://github.com/microsoft/TypeScript/issues/59601

    [2] https://bloomberg.github.io/ts-blank-space/

  2. 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
  3. proposal-type-annotations

    ECMAScript proposal for type syntax that is erased - Stage 1

    After almost a decade of TypeScript my recommendation is to not use TypeScript enums.

    Enums is going to make your TypeScript code not work in a future where TypeScript code can be run with Node.js or in browser when typings are added to JavaScript[1]

    Enums results in runtime code and in most cases you really want type enums. Use `type State = "Active" | "Inactive"` and so on instead. And if you really want an closed-ended object use `const State = { Active: 1, Inactive: 0 } as const`

    [1] https://github.com/tc39/proposal-type-annotations

  4. ts-blank-space

    A small, fast, pure JavaScript type-stripper that uses the official TypeScript parser.

    > Enums is going to make your TypeScript code not work in a future where TypeScript code can be run with Node.js

    Apparently they're planning on adding a tsconfig option to disallow these Node-incompatible features as well [1].

    Using this limited subset of TS also allows your code to compile with Bloomberg's ts-blank-space, which literally just replaces type declarations with blank spaces [2].

    [1] https://github.com/microsoft/TypeScript/issues/59601

    [2] https://bloomberg.github.io/ts-blank-space/

  5. fs-metadata

    Cross-platform native Node.js module for fetching filesystem metadata

    I've found this to be quite ergonomic and functional:

    https://github.com/photostructure/fs-metadata/blob/main/src/...

    Usage:

        export const Directions = stringEnum("North", "South", "East", "West")

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

  • Definite clause grammars and symbolic differentiation

    1 project | news.ycombinator.com | 12 Mar 2025
  • TypeScript: Getting Started With TSConfig Options

    1 project | dev.to | 12 Jan 2025
  • 7 Practical Tips to Minimize Your JavaScript Bundle Size

    1 project | dev.to | 29 Dec 2024
  • Advanced TypeScript: A Deep Dive into Modern TypeScript Development

    1 project | dev.to | 27 Dec 2024
  • How I start typescript.

    1 project | dev.to | 21 Dec 2024