What is an enum — and why JavaScript doesn't have one and TypeScript is moving away from it

Your code has an order status. Somewhere it's written "paid", somewhere "Paid", and in one place — "payed", with a typo. The program doesn't crash. It just quietly decides the order isn't paid and never ships it. You hunt that bug for an hour.
The enum — an enumeration — was invented against exactly this. And here's the unexpected part: JavaScript doesn't have one at all, while TypeScript does, but more and more teams avoid it. Let's see why, and what to write instead.
What an enum is
An enum is a closed list of allowed values with names. Not "any string", but "one of these".
Order status: new, paid, shipped, delivered. Four options, there is no fifth. Days of the week — seven. User role — guest, member, admin.
Once such a list is declared, you don't type the string by hand — you pick an option by name: Status.Paid. Typo in the name, and the editor underlines it immediately, before you run anything. It would have let the string "payed" slip through.
That's the whole benefit: the bug moves from your running app to the moment you're typing.
What it looks like in code
TypeScript has a dedicated enum keyword:
enum Status {
New = "new",
Paid = "paid",
Shipped = "shipped",
}
function ship(status: Status) { /* ... */ }
ship(Status.Paid); // fine
ship("payed"); // error right in the editor
Python has the enum module:
from enum import Enum
class Status(Enum):
NEW = "new"
PAID = "paid"
JavaScript has no enum keyword. There you usually make an object and freeze it:
const Status = Object.freeze({
New: "new",
Paid: "paid",
Shipped: "shipped",
});
Object.freeze stops anyone from accidentally adding a new option. But plain JavaScript still won't catch the typo in "payed" — the language has nothing to check it against. That's one of the reasons projects move to TypeScript. More in the TypeScript vs JavaScript comparison.
Why TypeScript is moving away from enum
Here's the surprise. Almost all of TypeScript's "type" part is simply erased when the code runs — plain JavaScript is left. But enum can't be erased: it turns into a real object with code.
That causes two problems.
First — a weird object. For a numeric enum, TypeScript builds a two-way table: name to number and number to name. Ask a two-option enum for its keys and you get four: ["0", "1", "Up", "Down"]. We checked this on the compiled code. A loop over that "enumeration" runs twice.
Second — it doesn't run everywhere. Node.js can now run TypeScript files directly by just stripping out the types. But it can't strip enum — and refuses. TypeScript 5.8 even added an erasableSyntaxOnly flag that forbids enum up front, so you find out in the editor instead of at runtime.
So the modern version looks like this:
const Status = {
New: "new",
Paid: "paid",
Shipped: "shipped",
} as const;
type Status = (typeof Status)[keyof typeof Status];
// "new" | "paid" | "shipped"
It's a plain object, plus as const, plus one line that pulls a type out of it. Typos are caught just the same. It erases without a trace. TypeScript's own docs say that in modern code you often don't need an enum — an object with as const is enough.
If you only need the options as types, it's even simpler — a list of strings joined with a bar:
type Role = "guest" | "member" | "admin";
When you'll need this
You'll meet enumerations wherever a field has a finite set of values: statuses, roles, plans, categories, sizes. Especially in AI-written code — models love scattering the same strings across ten files.
Noticed "admin" written in five places? That's an enumeration waiting to happen. Ask your agent:
Clean up the rolesUser roles are currently scattered as strings through the code ("admin", "member", "guest"). Move them into one Role object with as const in src/types/role.ts, derive a type from it, replace every string with Role.Admin and so on. Do not use enum. Show me the list of changed files.Checking the result is easy: search the project for the old "admin" string in quotes. If it's left in just one file, your enumeration is in place.
Is an enum the same as an array of options?
Similar, but no. An array holds values, while an enum also gives you a type: the editor knows there are no other options and suggests them by name. An array says nothing about what's allowed.
My project already uses enum — should I rewrite it?
Not necessarily. If the project builds with the regular TypeScript compiler, enum works. Rewrite when you want to run the code through Node without a build step, or when looping over the enum gives you extra keys.
String enum or numeric enum?
String. Its value is readable in logs and the database: "paid" means something, 1 doesn't. And a string enum has no two-way table, so no extra keys appear.
The AI Architect 2027 course: step by step from computer basics to your own app and first customers. 543 short lessons on your phone.





