Last active
April 24, 2025 20:02
-
Star
(160)
You must be signed in to star a gist -
Fork
(10)
You must be signed in to fork a gist
-
-
Save ciiqr/ee19e9ff3bb603f8c42b00f5ad8c551e to your computer and use it in GitHub Desktop.
zod optional/nullable/nullish differences
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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; | |
} |
Thanks, very good!
Niceee :)
Nice!
Thanks a lot!
Danke!
Thanks!
awesome
Thanks!
I thought I can chain like this:
field: z.string().nullable().optional(),
But this is the way:
field: z.string().nullish(),
I thought I can chain like this:
field: z.string().nullable().optional(),But this is the way:
field: z.string().nullish(),
Yes, I came to the same conclusions as you, .nullish() is what I was searching instead of .optional().
Thank you
Adding to the thanks train. Thank you!
Thank you
Thanks π
adamsΔ±n len
Thanks a lot. Real heros don't wear capes, they post wisdom on GitHub
thank you :)
thank you!
thank you :)
thank you !!!
thanks
π
Thanks!
Thanks !!
π
Here's another "Thank You".
π₯
bro thanks a bunch
Obrigado! π§π·
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Thanks!