Replies: 1 comment
-
The third generic is the Input type which defaults to the value of the output type (the first generic), so if you don't specify it, it requires that the input and output match, which is not the case for ZodDefault or ZodEffect. import { z } from "zod";
const Foo = z.string().default("foo");
type InputFoo = z.input<typeof Foo>;
type OutputFoo = z.infer<typeof Foo>;
const fooCopy: z.Schema<OutputFoo, z.ZodTypeDef, InputFoo> = Foo; I don't have a quick answer to the actual question here, but wanted to provide that quick bit of context. Hopefully that's helpful, but I'll try to take a swing at helping the broader question soon too. |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
I'm trying to write a generic wrapper for parse functions:
This unfortunately returns
Partial
on any schema or subschema that has a default.ZodType
behaves the same way.The closest I got based on #1310 is this:
However this introduces unwanted parameter for schema. I'm not returning a schema so I feel like this should be unnecessary.
I think the problem can be reduced to:
What would be the correct generic type for any kind of parseable schema that preserves output type?
Beta Was this translation helpful? Give feedback.
All reactions