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