Skip to content

prefer-multi-value-zod-literal

Use the Zod 4 multi-value literal API instead of a union of literal schemas.

Why

One multi-value literal expresses the same closed value domain without repeated schema wrappers.

Fix

Replace the union with z.literal([value1, value2, ...]).

Examples

Before — flagged Avoid repeated literal wrappers
src/schema.ts
import { z } from "zod/v4";
export const Version = z.union([z.literal(1), z.literal(2), z.literal(3)]);
After — preferred Use one multi-value literal
src/schema.ts
import { z } from "zod/v4";
export const Version = z.literal([1, 2, 3]);

Options

{
"additionalProperties": false,
"properties": {
"zodMajorVersion": { "maximum": 4, "minimum": 4, "type": "integer" }
},
"type": "object"
}