Skip to content

Instantly share code, notes, and snippets.

@ciiqr
Last active July 1, 2024 09:53
Show Gist options
  • Save ciiqr/ee19e9ff3bb603f8c42b00f5ad8c551e to your computer and use it in GitHub Desktop.
Save ciiqr/ee19e9ff3bb603f8c42b00f5ad8c551e to your computer and use it in GitHub Desktop.
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
{
optional?: string | undefined;
nullable: string | null;
nullish?: string | null | undefined;
}
@MarceloRab
Copy link

thank you :)

@dannydi12
Copy link

Yes!!

@wakeupmh
Copy link

thanks mate

@sergiolg98
Copy link

thanks mate!

@saileshbro
Copy link

Thanks mate!

@ablade-py
Copy link

thanks mate!

@izaakwalz
Copy link

Thanks!

@zhondori
Copy link

Thank you

@spock123
Copy link

Beautiful

@christianjjc
Copy link

THANKS A LOT!!!!

@emilienbidet
Copy link

Thank you !

@zechdc
Copy link

zechdc commented May 22, 2024

Thanks!

@rodrigoaraujo7
Copy link

Thanks, very good!

@filippofilip95
Copy link

Niceee :)

@marcelocmenezes
Copy link

Nice!

@adwait-godbole
Copy link

Thanks a lot!

@khobiziilyes
Copy link

Danke!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment