This file contains 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
z.string().optional().array(); // (string | undefined)[] | |
z.string().array().optional(); // string[] | undefined |
This file contains 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
mySchema.safeParse(""I am a valid password""); // => { success: true; data: "I am a valid password" } | |
mySchema.safeParse(""); // => { success: false; error: ZodError } |
This file contains 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
const result = User.parse({ | |
email: "[email protected]", | |
name: "Hello World" | |
}); |
This file contains 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
[ | |
{ | |
"code": "invalid_type", | |
"expected": "number", | |
"received": "undefined", | |
"path": [ | |
"phoneNumber" | |
], | |
"message": "Required" | |
} |
This file contains 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
import { z } from "zod"; | |
const User = z.object({ | |
email: z.string().email(), | |
name: z.string(), | |
phoneNumber: z.number() | |
}); |
This file contains 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
[ | |
{ | |
"code": "too_small", | |
"minimum": 1, | |
"type": "string", | |
"inclusive": true, | |
"message": "Should be at least 1 characters", | |
"path": [] | |
}, | |
{ |
This file contains 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
import { z } from "zod"; | |
const stringSchema = z.string().nonempty().min(8).max(32); | |
stringSchema.parse(""); | |
stringSchema.parse(""); // throws an exception | |
stringSchema.parse("I am a valid password"); // returns "I am a valid password" |
This file contains 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
const User = z.object({ | |
email: z.string().email(), | |
name: z.string(), | |
phoneNumber: z.number() | |
}); | |
const Hobby = z.object({ | |
hobbyName: z.string().min(1) | |
}); | |
const Hobbyist = User.merge(Hobby); | |
const result = Hobbyist.safeParse({ |
This file contains 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
import { z } from "zod"; | |
const stringSchema = z.string().nonempty().min(8).max(32); | |
stringSchema.parse(""); | |
stringSchema.parse(""); // throws an exception | |
stringSchema.parse("I am a valid password"); // returns "I am a valid password" |
This file contains 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
import React, { Suspense } from "react"; | |
import { GET_LAUNCHES } from "./queries"; | |
import { useAPI } from "./useAPI"; | |
const Launches = ({ launches }) => { | |
return ( | |
<div> | |
{launches.read().launchesPast.map((item) => ( | |
<div> | |
<h1>{item.mission_name}</h1> |
NewerOlder