Created
April 4, 2023 08:57
-
-
Save onion2k/71fb5523c5f3b41ee8f67d4000ae7c4f to your computer and use it in GitHub Desktop.
A zod validator that uses input and output
This file contains hidden or 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 MyFunctionProps = z.object({ | |
| date: z | |
| .string() | |
| .datetime() | |
| .transform((str) => new Date(str)) | |
| }); | |
| function MyFunction(props: z.input<typeof MyFunctionProps>): z.output<typeof MyFunctionProps> { | |
| const { date } = MyFunctionProps.parse(props); | |
| return { date }; | |
| } | |
| MyFunction({ date: '2022-01-01' }); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment