Skip to content

Instantly share code, notes, and snippets.

@ciiqr
Last active July 16, 2025 15:41
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;
}
@IlhomYuldoshev
Copy link

thank you :)

@flunetS
Copy link

flunetS commented Nov 29, 2024

thank you !!!

@dylan1951
Copy link

thanks

@temich
Copy link

temich commented Dec 18, 2024

👍

@eric-lesslie
Copy link

Thanks!

@sCuz12
Copy link

sCuz12 commented Jan 17, 2025

Thanks !!

@krizh-p
Copy link

krizh-p commented Feb 2, 2025

👍

@ogrotten
Copy link

Here's another "Thank You".

@bramswenson
Copy link

🥇

@RadoslavTsvetanov
Copy link

bro thanks a bunch

@becelli
Copy link

becelli commented Mar 30, 2025

Obrigado! 🇧🇷

@aldidas
Copy link

aldidas commented May 4, 2025

Thanks, very helpful!

@rodrigoantas
Copy link

thanks!

@LaPulgaaa
Copy link

thanks

@PV-Sachidanand
Copy link

Nice!!!!!!!

@madisonrubylee
Copy link

thanks

@Dhyrkas
Copy link

Dhyrkas commented Jul 16, 2025

Thanks

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