Skip to content

Instantly share code, notes, and snippets.

@iskenxan
Created January 17, 2022 14:29
Show Gist options
  • Save iskenxan/0bb3453b881045659f8ec0014fd80490 to your computer and use it in GitHub Desktop.
Save iskenxan/0bb3453b881045659f8ec0014fd80490 to your computer and use it in GitHub Desktop.
composing-schemas-zod.ts
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({
email: "hi@sample.com",
name: "Hello World",
phoneNumber: 123
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment