Skip to content

Instantly share code, notes, and snippets.

@onion2k
Created April 4, 2023 08:57
Show Gist options
  • Select an option

  • Save onion2k/71fb5523c5f3b41ee8f67d4000ae7c4f to your computer and use it in GitHub Desktop.

Select an option

Save onion2k/71fb5523c5f3b41ee8f67d4000ae7c4f to your computer and use it in GitHub Desktop.
A zod validator that uses input and output
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