Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Infer types from zod schema #429

Closed
victormamede opened this issue Jul 15, 2022 · 2 comments · May be fixed by #653
Closed

Infer types from zod schema #429

victormamede opened this issue Jul 15, 2022 · 2 comments · May be fixed by #653

Comments

@victormamede
Copy link

Is your feature request related to a problem? Please describe.
Zod automatically infers the typescript type from schema, so I declare my FieldValues like this:

type FieldTypes = z.infer<typeof schema>

and then:

const {...} = useForm<FieldTypes>({
  resolver: zodResolver(schema),
});

But I feel like the useForm hook should be abre to infer the type, since the useForm's resolver uses the generic TFieldValues Resolver<TFieldValues, TContext>

Describe the solution you'd like
The zodResolver should automatically infer TFieldValues given a zod schema

Describe alternatives you've considered
Using useForm<z.infer<typeof schema>> but I think this is ugly

@bluebill1049
Copy link
Member

resolver is a generic function to resolve validation schema results, unless this can be applied to all schema, we probably not going to make except or tight integration with any schema lib, however, you probably build your own custom resolver to achieve that instead. https://codesandbox.io/s/react-hook-form-customresoliver-v7-8mpqw

@punkpeye
Copy link

@victormamede Did you figure out how to make this work with Zod?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants