Developer Tools

TypeScript Enum Generator

Turn a list of names into a TypeScript enum, or into the as const object that many teams now prefer because it is plain JavaScript and works with every build tool. Choose string or numeric values, and add a list of all values, display labels checked by the compiler and a type guard for validating input.

  • Runs in your browser
  • No sign-up
  • Free to use
Start from an example

Write Name or Name = value. Numbers continue counting from the last value, as in TypeScript.

Helpers

    How to use TypeScript Enum Generator

    1. Enter the enum name and members, one per line.
    2. Choose the style and how string values are written.
    3. Tick the helpers you need.
    4. Copy the TypeScript.

    TypeScript Enum Generator features

    Five styles

    as const object, string enum, numeric enum, const enum or union.

    Value casing

    snake_case, kebab-case, UPPER_CASE, camelCase or as named.

    Numeric counting

    Continues from explicit values, like TypeScript does.

    Value list

    All values as an array for menus and validation.

    Labels

    Record<Enum, string> so a missing label is a compile error.

    Type guard

    isRole(value) for checking unknown input.

    When to use TypeScript Enum Generator

    • Defining roles, statuses or categories.
    • Mapping HTTP status codes or error codes to names.
    • Migrating enums to as const objects for Vite, esbuild or Node.js type stripping.
    • Building dropdowns with labels from one definition.

    TypeScript Enum Generator FAQ

    Should I use enum or an as const object?

    Both give named constants and a type. The as const object is ordinary JavaScript, so it works with type stripping in Node.js, the erasableSyntaxOnly option and every bundler. Enums need TypeScript’s compiler to emit code.

    What is wrong with const enum?

    Nothing in a single project compiled by tsc, but tools that compile files in isolation (Babel, esbuild, SWC, Vite) cannot inline const enums imported from other files.

    Why prefer string values?

    Strings are readable in logs, databases and network traffic. Numeric enums also have a reverse mapping, which makes Object.values return names as well as numbers.

    How do the labels help?

    Because the labels object is typed Record<Role, string>, adding a member without a label is a compile error.

    Can values be given explicitly?

    Yes. Write Name = value. For numeric enums, following members continue counting from that number.

    Is anything uploaded?

    No. Everything runs in your browser.

    Enums in TypeScript

    Enums give names to a fixed set of values. TypeScript’s enum keyword was one of its first features, and it produces both a type and a runtime object. Over time the community has become more cautious about it: enums are one of the few TypeScript features that generate JavaScript code, which matters for tools that simply strip types.

    The modern alternative is an object declared with as const, together with a type derived from its values. Code reads the same, Role.Admin, and the type Role is the union of the values. Because it is plain JavaScript, it works with Node.js running TypeScript directly, with the erasableSyntaxOnly compiler option and with every bundler, which is why this generator recommends it.

    When the enum keyword is the right choice, the generator writes string enums, numeric enums and const enums. For numeric enums it follows TypeScript’s counting rule: members without a value continue from the previous one. The notes explain the trade-offs, such as the reverse mapping of numeric enums and the isolated-modules limitation of const enums.

    Values are generated from the member names in the casing you choose, because what is stored in a database or sent over the network rarely uses PascalCase. You can also give any value explicitly.

    Helpers turn the enum into something an application can use: a list of all values for menus and validation, a labels object whose Record type makes the compiler insist on a label for every member, and a type guard that checks whether an unknown value, such as a query parameter, is a valid member.

    Other useful tools