steep-army-61520
10/12/2025, 2:53 AMparse method offered by zod.white-nest-40686
10/12/2025, 9:13 AMsteep-army-61520
10/12/2025, 11:45 PMwhite-nest-40686
10/13/2025, 8:17 AMts
const UserSchema = z.object({
name: z.string(),
age: z.number(),
email: z.string().email(),
address: z.object({
street: z.string(),
city: z.string(),
zip: z.string().length(5)
})
})
const user1 = { name: 'john', email: 'email' }
const user2 = UserSchema.safeParse(user1)
if (!user2.success) {
// handle error then return
console.log(user2.error);
} else {
// do something
console.log(user2.data);
}
I know it's not a great solution.
Exactly why do you need to use Zod for validation? Is it not sufficient to just use types?steep-army-61520
10/13/2025, 4:01 PMwhite-nest-40686
10/13/2025, 11:54 PM