Skip to content

Instantly share code, notes, and snippets.

@ciiqr
Last active April 25, 2024 22:36
Show Gist options
  • Star 67 You must be signed in to star a gist
  • Fork 6 You must be signed in to fork a gist
  • 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;
}
@ozzyfromspace
Copy link

Thanks!

@danielkellyio
Copy link

very useful. Thanks!

@1Mouse
Copy link

1Mouse commented Sep 6, 2023

this is brilliant

@xxshady
Copy link

xxshady commented Sep 28, 2023

👍

@MBelniak
Copy link

MBelniak commented Oct 2, 2023

Thanks :)

@Strajk
Copy link

Strajk commented Oct 29, 2023

hero! ⭐️

@aryanprince
Copy link

Thank you so much! Very helpful! 💯

@sahilahluwalia
Copy link

very helpful!

@axmad386
Copy link

Oh I see, now it's time to refactor all the schema 🤣
Thanks bro, you are the best

@bashidagha
Copy link

thanks bro

@arr199
Copy link

arr199 commented Dec 21, 2023

thank you

@noahbaron91
Copy link

thank you!!!

@starkblaze01
Copy link

thank you :)

@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

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