Skip to content

TypeScript · maintainability

no-zod-native-enum

eslint:no-zod-native-enum

Disallow `z.nativeEnum()` (and `z.enum()` over a TypeScript enum); use `z.enum(["a", "b"])` with a string-literal union instead.

Default
error
Fix
safe
Languages
typescript

Why

Wrapping a TypeScript enum preserves its emitted runtime object and duplicates the schema's value definition across two constructs.

Fix

Pass string literals directly to `z.enum` and derive the TypeScript type with `z.infer`.

Before / after

Executed by this rule’s unit tests.

Before

Do not wrap a TypeScript enum

src/status.ts · focus
import { z } from "zod"; const S = z.nativeEnum({ Active: "active", Inactive: "inactive" });
Autofix output
src/status.ts
import { z } from "zod"; const S = z.enum(["active", "inactive"]);

After

Declare string values directly in Zod

src/status.ts · focus
import { z } from "zod"; const S = z.enum(["active", "inactive"]);

Limits

  • Automatic fixes are limited to inline object literals whose unique values are all string literals.

Message IDs

enumOfTsEnumnativeEnum