Skip to content

Missing Date variant in types of too small/big errors #5350

@gebsh

Description

@gebsh

Interfaces $ZodIssueTooSmall and $ZodIssueTooBig type minimum and maximum properties respectively as number | bigint:

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():

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"];

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

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions