Skip to content
Sarj Code Standards

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

Use z.literal([value1, value2, ...]) for a modern Zod 4 value-domain contract. Preserve required union introspection or error-shape contracts with an explained local exception.

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": {
"description": "Installed Zod major version used to validate multi-value literal support.",
"maximum": 4,
"minimum": 4,
"type": "integer"
}
},
"type": "object"
}