Enum to Union Converter
Paste one or more TypeScript enums and instantly get the modern, tree-shakeable replacement: a const object asserted with as const plus a derived union type. Toggle between five outputs — const-object + union, a value union, a key union, an as-const values array, or a forward/reverse mapping — and read a live lint panel that flags numeric reverse-map footguns, mixed value types, const-enum portability issues, and duplicate values.
About this ToolHow it works, benefits & use casesTap to collapse
TypeScript enums emit real JavaScript at runtime, which means they cannot be erased under erasableSyntaxOnly, they trip up isolatedModules and bundlers that try to tree-shake, and numeric enums quietly add a two-way reverse map. This converter parses one or more enums — numeric auto-increment, explicit numbers, string values, const enum, and inline comments — and rewrites them into the modern alternatives. You can toggle between five outputs: the recommended const object asserted with as const plus a derived typeof X[keyof typeof X] union, a plain literal union of the values, a union of the member keys, an as-const values array with an indexed union, or a forward and reverse mapping pair. A live lint panel flags the things that bite during a migration: numeric reverse-map footguns, mixed value types, duplicate values, and const enum portability. Everything updates instantly as you type, runs entirely in your browser, and is captured in a shareable URL.
How to Use
- 1Paste one or more TypeScript enums into the input, or load one of the examples (string, numeric, const enum, mixed, or two enums).
- 2Pick an output mode: const + union (recommended), value union, key union, values array, or mapping.
- 3Toggle Preserve values to switch between the enum values and the bare member names as the literals.
- 4Toggle Export declarations to add or drop the export keyword on the generated code.
- 5Read the Notes panel for any reverse-map, mixed-type, duplicate-value, or const-enum warnings, then copy, download, or share the result.
Key Benefits
- Parses several enums at once, including numeric auto-increment, explicit numbers, string values, and const enum
- Keeps inline member comments and carries them into the const object output
- Five output modes: const object + union, value union, key union, as-const values array, and forward/reverse mapping
- Recommends the tree-shakeable const object + as const pattern that erases cleanly under erasableSyntaxOnly
- Live lint panel flags numeric reverse-map footguns, mixed value types, duplicate values, and const enum portability issues
- Instant live output with stats (enums, members, numeric, string) and a shareable URL
- Runs entirely in the browser — your code is never uploaded
Common Use Cases
- Migrating a codebase off TypeScript enums to the const object + union pattern
- Adopting isolatedModules, erasableSyntaxOnly, or a Babel/esbuild pipeline that does not support enums
- Replacing a numeric enum to remove its surprising runtime reverse map
- Generating a values array for runtime iteration alongside a narrow union type
- Building a forward and reverse lookup map from an existing enum
- Auditing an enum for duplicate values or mixed string/number members before refactoring
Recommended: const object as const + derived union
export const Status = {
Active: 'ACTIVE',
Inactive: 'INACTIVE',
Pending: 'PENDING',
Archived: 'ARCHIVED',
} as const;
export type Status = (typeof Status)[keyof typeof Status];TypeScript enum
Numeric auto-increment, explicit numbers, string values, const enum and inline comments are all handled. Paste several enums at once.
Options
Use each member's value; off = use the name
Prefix output with export
Why replace enums with a const object
A TypeScript enum emits real JavaScript at runtime, so it cannot be erased by erasableSyntaxOnly and bloats output that bundlers struggle to tree-shake. The const object + as const pattern keeps the same ergonomics with zero runtime cost beyond a plain object, and the derived typeof X[keyof typeof X] union gives you the same narrow type.
Numeric enums hide a reverse map
Numeric enums compile to a two-way object where X[0] === 'Active' and X.Active === 0 both exist — surprising for iteration and serialization. The notes panel flags this and the other footguns (mixed value types, duplicate values, const enum portability).
Was this tool helpful?
Share Your Experience
Help others discover this tool!
Related tools
- TypeScript FormatterFormat and beautify TypeScript code
- Color ConverterConvert between HEX, RGB, HSL, and HSV
- cURL to Code ConverterConvert cURL commands to code in various languages
- HTML to MarkdownConvert HTML to Markdown
- JSON to CSVConvert JSON to CSV format
- npm to Yarn ConverterConvert npm commands and package-lock.json to Yarn equivalents
A const object plus as const gives you the same dot-access ergonomics (X.Active) and the same narrow literal type via typeof X[keyof typeof X], but it is just a plain object at runtime. That means it tree-shakes well, works under isolatedModules, and is fully erasable when only the type is used — none of which is true for a real enum, which always emits a runtime helper.
A numeric enum compiles to a two-way object: both X.Active === 0 and X[0] === "Active" exist. That extra reverse mapping is easy to forget when you iterate the keys, serialize the value, or validate input, and it produces entries you did not write. The Notes panel flags numeric enums for this reason, and the const object output keeps a one-way lookup with no surprise reverse keys.

