Skip to content

Instantly share code, notes, and snippets.

View shawnmclean's full-sized avatar
🐭
:)

Shawn Mclean shawnmclean

🐭
:)
View GitHub Profile
@shawnmclean
shawnmclean / zod-optional-null.ts
Created September 28, 2024 17:12 — forked from ciiqr/zod-optional-null.ts
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
{
@shawnmclean
shawnmclean / gist:1937486
Created February 29, 2012 03:56 — forked from anonymous/gist:1937453
a guest on Feb 28th, 2012 - pastebin.com/5ciDhb6V
myObj = this;
someMethod = function(){
myObj.myProp;
}