zod icon indicating copy to clipboard operation
zod copied to clipboard

Inconsistent input/output behavior between examples - is this intentional design?

Open LiST-GIT opened this issue 7 months ago • 2 comments

const j = zod.null().transform(() => () => { });
let j1: zod.input<typeof j>; // null
let j2: zod.output<typeof j>; // () => void
let k = zod.function().args(j);
let k1: zod.input<typeof k>; // (args_0: () => void, ...args: unknown[]) => unknown
let k2: zod.output<typeof k>; // (args_0: null, ...args: unknown[]) => unknown

In this example, the input and output in 'j' are reversed compared to 'k'. I'd like to know if this contradictory behavior is intentionally designed this way?

LiST-GIT avatar May 20 '25 07:05 LiST-GIT

zod version: 3.25.7

LiST-GIT avatar May 20 '25 07:05 LiST-GIT

let i = zod.function().args(zod.string().optional());
i.parameters().parse([]); // ZodError: too_small

When a string is defined as optional, inputting an empty array ([]) should be considered valid. Is this the expected behavior?

LiST-GIT avatar May 20 '25 07:05 LiST-GIT

This is correct & intended.

colinhacks avatar Jun 04 '25 04:06 colinhacks