You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Describe the bug
When using zodResolver with a schema that includes type transformations (like z.coerce.number()), TypeScript shows a type error due to incompatibility between the input type and the transformed output type.
To Reproduce
Steps to reproduce the behavior:
Create a form with string inputs that should be transformed to numbers
Define a Zod schema using z.coerce.number()
Set up a useForm hook with proper generics for input and output types
Expected behavior
The zodResolver should properly handle the type transformation from the input type to the output type without TypeScript errors. It should recognize that the input type (string) will be transformed to the output type (number) according to the Zod schema's coercion rules.
Screenshots
Additional context
This issue seems to have been introduced by PR #739
While this PR aimed to improve type inference for resolvers, it appears to have created a new problem when using z.coerce transformations with different input and output types. Before this change, the types were more flexible, but now the strict type checking causes errors when form values (strings) are coerced to different types (numbers) by the Zod schema.
The text was updated successfully, but these errors were encountered:
chida09
changed the title
Type error when using zodResolver with z.coerce transformations
Type error when using zodResolver with z.coerce transformations since v4.1.0
Feb 26, 2025
Describe the bug
When using
zodResolver
with a schema that includes type transformations (likez.coerce.number()
), TypeScript shows a type error due to incompatibility between the input type and the transformed output type.To Reproduce
Steps to reproduce the behavior:
Codesandbox link (Required)
https://codesandbox.io/p/sandbox/ns3wp2?file=%2Fsrc%2FApp.tsx
Expected behavior
The zodResolver should properly handle the type transformation from the input type to the output type without TypeScript errors. It should recognize that the input type (string) will be transformed to the output type (number) according to the Zod schema's coercion rules.
Screenshots
Additional context
This issue seems to have been introduced by PR #739
While this PR aimed to improve type inference for resolvers, it appears to have created a new problem when using z.coerce transformations with different input and output types. Before this change, the types were more flexible, but now the strict type checking causes errors when form values (strings) are coerced to different types (numbers) by the Zod schema.
The text was updated successfully, but these errors were encountered: