You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Exhaustive z.record() accepts a missing key when the value schema accepts undefined #6769
z.record(z.literal("a"), z.any()).safeParse({}) succeeds, and so does z.record(z.enum(["a", "b"]), z.unknown()).safeParse({ a: 1 }), while z.object({ a: z.any() }).safeParse({}) fails. The docs say Zod "will exhaustively check that all enum values exist in the input as keys", and that a value schema that can stand in for an absent key (.default(), .prefault(), .optional()) makes the key optional, "the same as it does inside z.object()". z.input types the key as required and z.toJSONSchema() lists it in required. The exhaustive branch of $ZodRecord runs the value schema on input[key] without checking that the key is present, and the compiled record has the same gap.
Activity