-
-
Notifications
You must be signed in to change notification settings - Fork 1.7k
Open
Description
Interfaces $ZodIssueTooSmall and $ZodIssueTooBig type minimum and maximum properties respectively as number | bigint:
zod/packages/zod/src/v4/core/errors.ts
Lines 26 to 44 in 3b94610
| export interface $ZodIssueTooBig<Input = unknown> extends $ZodIssueBase { | |
| readonly code: "too_big"; | |
| readonly origin: "number" | "int" | "bigint" | "date" | "string" | "array" | "set" | "file" | (string & {}); | |
| readonly maximum: number | bigint; | |
| readonly inclusive?: boolean; | |
| readonly exact?: boolean; | |
| readonly input?: Input; | |
| } | |
| export interface $ZodIssueTooSmall<Input = unknown> extends $ZodIssueBase { | |
| readonly code: "too_small"; | |
| readonly origin: "number" | "int" | "bigint" | "date" | "string" | "array" | "set" | "file" | (string & {}); | |
| readonly minimum: number | bigint; | |
| /** True if the allowable range includes the minimum */ | |
| readonly inclusive?: boolean; | |
| /** True if the allowed value is fixed (e.g.` z.length(5)`), not a range (`z.minLength(5)`) */ | |
| readonly exact?: boolean; | |
| readonly input?: Input; | |
| } |
This misses the Date variant that occurs at runtime when validating z.date().min() or z.date().max():
zod/packages/zod/src/v4/core/checks.ts
Lines 64 to 68 in 3b94610
| export const $ZodCheckLessThan: core.$constructor<$ZodCheckLessThan> = /*@__PURE__*/ core.$constructor( | |
| "$ZodCheckLessThan", | |
| (inst, def) => { | |
| $ZodCheck.init(inst, def); | |
| const origin = numericOriginMap[typeof def.value as "number" | "bigint" | "object"]; |
zod/packages/zod/src/v4/core/checks.ts
Lines 55 to 59 in 3b94610
| const numericOriginMap = { | |
| number: "number", | |
| bigint: "bigint", | |
| object: "date", | |
| } as const; |
For example, running the following code logs Date despite issue.minimum being typed as number | bigint:
import * as z from "zod";
const schema = z.date().min(new Date("2025-01-01"));
const result = schema.safeParse(new Date("2020"), {
error: (issue) => {
if (issue.code === "too_small") {
console.log(issue.minimum.constructor.name);
}
return "";
},
});Metadata
Metadata
Assignees
Labels
No labels