Skip to main content

TypeScript Enum Generator

Turn a pasted list of values into a TypeScript enum, const enum, as-const object, or union type. Auto-sanitizes member names into valid identifiers (handles spaces, punctuation, and digit-leading values), picks a key casing style, and can add JSDoc comments, a type guard, a values array, or a reverse-lookup map.

Input

Output

TypeScript Output
 
Was this helpful?

Guides

Paste a list of values and get back ready-to-use TypeScript — a string enum, a numeric enum, a const enum, an as const object, or a union type. It turns a status list or a set of category names into type-safe TypeScript in one paste, without you hand-writing member names or worrying about what makes an identifier valid.

How it works

  1. Paste values into the input box, one per line (or comma-separated — the separator is auto-detected).
  2. Set an Enum Name, a Key Naming Style (PascalCase, SCREAMING_SNAKE_CASE, or camelCase), and an Output Format:
    • String Enumenum Status { Active = "ACTIVE" }
    • Numeric Enumenum Status { Active = 0 }, auto-incrementing from zero
    • Const Enum (string) — a const enum, inlined at compile time, no runtime object
    • as const Object — a plain object plus a derived union type, for codebases that avoid enum
    • Union Type — a string literal union with no runtime value, e.g. type Status = "ACTIVE" | "INACTIVE"
  3. Optionally add JSDoc comments (one per member), a type guard function (isStatus(value)), an array of all values, or — for numeric enums only — a reverse lookup map from member to its original label.

The result updates as you type or change an option, ready to copy or download as enum.ts.

Identifier sanitization

TypeScript member names can't contain spaces or punctuation, and can't start with a digit. Pasted values rarely arrive pre-formatted, so the tool auto-converts them into valid identifiers instead of emitting broken syntax:

  • Spaces and punctuation become word breaks, folded into your chosen casing style — "in progress" becomes InProgress, IN_PROGRESS, or inProgress.
  • A value starting with a digit gets an underscore prefix once cased ("2nd place"_2ndPlace), since 2ndPlace isn't a legal identifier start.
  • A value matching a reserved keyword (class, async, type, and so on) gets a trailing underscore (classclass_).
  • Duplicate keys — two values that sanitize to the same identifier — get a numeric suffix (Active, Active2, Active3) so the output always compiles.
  • The Enum Name field gets the same treatment: 2 Ranks becomes _2Ranks rather than invalid syntax.

String enum values use a simpler transform: uppercased, with runs of non-alphanumeric characters collapsed to a single underscore ("in progress""IN_PROGRESS").

Why not just reject bad input?

Values pasted from a spreadsheet or a status list are almost never already valid identifiers. Rejecting them would just push the cleanup work back onto you; auto-converting means the output always compiles, and you can rename anything you don't like afterward.

What's the difference between an enum, a const enum, and a union type?

A regular enum compiles to a real object you can inspect at runtime (Object.values(Status)). A const enum is erased at compile time — every reference inlines to its literal value, adding nothing to your bundle but losing runtime iteration. A union type ("ACTIVE" | "INACTIVE") is compile-time-only with zero runtime footprint — many style guides prefer it over enum for that reason. The as const object sits in between: a real runtime object plus a derived union type, without enum's bidirectional numeric-mapping quirks.

This tool runs entirely in your browser — pasted values are never sent to a server.

typescriptenumcodegendevelopertypes

Love the tools? Lose the ads.

One payment clears every ad from your account, for good. No subscription, no tracking.