Skip to content

TypeScript · correctness

no-impossible-zod-literal-bounds

eslint:no-impossible-zod-literal-bounds

Disallow same-chain literal Zod bounds whose accepted set is mathematically empty.

Default
error
Fix
none
Languages
typescript

Why

A schema with contradictory literal bounds rejects every input, turning validation into an unreachable contract that usually reflects a typo.

Fix

Choose compatible lower and upper bounds, or remove the constraint that does not express the intended domain.

Before / after

Executed by this rule’s unit tests.

Before

Reject an empty numeric interval

src/schema.ts · focus
import { z } from "zod"; const S = z.number().min(5).max(4);

After

Allow a number admitted by both bounds

src/schema.ts · focus
import { z } from "zod"; const S = z.number().gte(3).lte(3);

Limits

  • Only finite numeric literals in a single number, string, or array schema chain are compared.
  • Chains with dynamic bounds, non-bound validators, transforms, pipes, or preprocessors are skipped.
  • Test and generated files are excluded.

Message IDs

impossibleBounds