Skip to content

Instantly share code, notes, and snippets.

View bchilcott's full-sized avatar

Ben Chilcott bchilcott

  • Hargreaves Lansdown
  • United Kingdom
View GitHub Profile
@ciiqr
ciiqr / zod-optional-null.ts
Last active November 14, 2024 19:28
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
{