Skip to content

no-ts-enum ​

TypeScript's enum is not allowed.

Why: it is the one TypeScript feature that emits runtime code, a numeric enum accepts any number (const s: Status = n compiles for any n: number, member or not), and Node's built-in TypeScript support can't run it. Guide: Enums.

✕ Rejectedno-ts-enum
ts
export enum Status {
  Draft,
  Published,
}

export function isLive(status: Status): boolean {
  return status === Status.Published;
}

✅ Accepted: a union of strings, for named constants

✓ Accepted0 diagnostics
ts
export type Status = "draft" | "published";

export function isLive(status: Status): boolean {
  return status === "published";
}

✅ Accepted: Enum, when variants carry data

✓ Accepted0 diagnostics
ts
import { constructors, type Enum, is } from "@evobug_com/safe-ts-std/enum";

export type Status = Enum<{ Draft: {}; Published: { at: string }; Archived: { reason: string } }>;
export const Status = constructors<Status>();

export function isLive(status: Status): boolean {
  return is(status, Status.Published);
}
ts
import { constructors, type Enum, is } from "@evobug_com/safe-ts-std/enum";

export type Status = Enum<{ Draft: {}; Published: { at: string }; Archived: { reason: string } }>;
export const Status = constructors<Status>();

export function isLive(status: Status): boolean {
  return (status?.tag === "Published");
}

Quick fix: Convert to a const object + union type. Code using Status.Published and the type Status keeps working, with the same values. Not offered for a numeric enum the file reads as an object (Status[0], Object.keys(Status)): a numeric enum is also a reverse mapping (Status[0] is "Draft"), which the const object doesn't have:

✓ Accepted0 diagnostics
ts
export const Status = { Draft: 0, Published: 1 } as const;
export type Status = (typeof Status)[keyof typeof Status];

export function isLive(status: Status): boolean {
  return status === Status.Published;
}

The fix is only offered when every member's value is a literal.

MIT OR Apache-2.0 · Docs by Gemini 4 Neon Extra