Skip to content

Instantly share code, notes, and snippets.

View CutiePi's full-sized avatar
💾

Jasmin Lapointe CutiePi

💾
View GitHub Profile
@ciiqr
ciiqr / zod-optional-null.ts
Last active November 19, 2024 06:54
zod optional/nullable/nullish differences
// zod schema
z.object({
// valid if string or:
optional: z.string().optional(), // field not provided, or explicitly `undefined`
nullable: z.string().nullable(), // field explicitly `null`
nullish: z.string().nullish(), // field not provided, explicitly `null`, or explicitly `undefined`
});
// type
{