Skip to content

fix(zod): update return type in zodResolver to use z.input instead of… #749

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

Closed

Conversation

diegotraid
Copy link

Resolves #743

For the function zodResolver to return a type compatible with react-hook-form, it must return Resolver<z.input<typeof schema>> instead of Resolver<z.infer<typeof schema>>.

@controversial
Copy link

Is it possible for useForm to also infer the TTransformedValues parameter from the Resolver? or can useForm only pick up the TFieldValues input shape from the Resolver?

@diegotraid diegotraid marked this pull request as draft February 24, 2025 21:04
@diegotraid
Copy link
Author

Is it possible for useForm to also infer the TTransformedValues parameter from the Resolver? or can useForm only pick up the TFieldValues input shape from the Resolver?

That, I think, it's the main issue here.
I think resolvers doesn't take transformed values into consideration:

export type Resolver<TFieldValues extends FieldValues = FieldValues, TContext = any>

While useForm does:
useForm<TFieldValues extends FieldValues = FieldValues, TContext = any, TTransformedValues extends FieldValues | undefined = undefined>

@controversial
Copy link

At the very least, this PR will be an improvement over the current situation

@diegotraid
Copy link
Author

Waiting for react-hook-form/react-hook-form#11951 to be merged into master to provide a more correct solution to this.

@controversial
Copy link

That PR was merged into react-hook-form’s main 3 days ago I believe

@jorisre
Copy link
Member

jorisre commented Feb 25, 2025

Hi everyone,

Thank you for your contributions. A PR was merged a few days ago, but the work is still ongoing. I'm currently working on RHF and resolvers to implement type inference, (Input vs. Output/Transformed Values from the schema).

Unfortunately, while this PR resolves one issue, it has created another. At this point, both libraries (RHF & resolvers) need to evolve.

Please keep an eye out for upcoming PRs—your reviews and feedback will be greatly appreciated.

@controversial
Copy link

Thanks for your hard work @jorisre!

@diegotraid
Copy link
Author

Closing since this is being resolved with PR #753

@diegotraid diegotraid closed this Feb 28, 2025
@diegotraid diegotraid deleted the fix-zod-type-inference branch February 28, 2025 00:06
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 this pull request may close these issues.

Zod resolver infered types are incorect since 4.1.0
3 participants