Skip to content

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.

Why

The project prefers literal-first schema definitions. nativeEnum also accepts plain enum-like objects, so this is an explicit declaration policy, not proof that every call duplicates a TypeScript enum's runtime object.

Fix

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

Examples

Before — flagged Do not wrap a TypeScript enum
src/status.ts
import { z } from "zod";
const S = z.nativeEnum({ Active: "active", Inactive: "inactive" });
After — preferred Declare string values directly in Zod
src/status.ts
import { z } from "zod";
const S = z.enum(["active", "inactive"]);