Skip to content
Sarj Code Standards

no-invalid-zod-custom-parse

Do not parse an incompatible primitive literal through an unvalidated Zod custom schema.

Why

Without a validator, z.custom<T>() returns its input unchanged while promising T. A parsed primitive outside that value domain fabricates a contract the caller may trust.

Fix

Provide actual validation, use the appropriate primitive schema, or retain an honest unknown result until validation. Preserve composed validators and independently owned domain contracts.

Examples

Before — flagged An unchecked parser returns the number unchanged
src/value.ts
import { z } from "zod";
const value = z.custom<string>().parse(1);
After — preferred Validate a primitive at the boundary
src/value.ts
import { z } from "zod";
const value = z.custom<string>((value) => typeof value === "string").parse(1);

References