Skip to content

Assign TFieldsValues to fieldsValues instead of transformedValues - #47

Merged
aspirisen merged 1 commit into
react-hook-form:mainfrom
SeokminHong:fix-transform-type
Sep 30, 2025
Merged

aspirisen merged 1 commit into
react-hook-form:mainfrom
SeokminHong:fix-transform-type

Conversation

@SeokminHong

Copy link
Copy Markdown
Contributor

Resolves #39

Support for the TransformedValues type was raised in issue #34. The example in that issue showed that when using Zod together with @hookform/resolvers/zod, there is no type support when the input and output differ.

This was addressed in commit fc6c0a4 by passing TransformedValues to the generic of useLens instead of the control鈥檚 FieldValues. However, a lens only deals with the input side of the form and does not concern itself with the submission type after resolution, so this change is inappropriate.

Suppose we have a Zod schema like the following.

const FormSchema = z.object({
  a: z.string().transform(value => Number.parseInt(value, 10)),
});
type FormInput = z.input<typeof FormSchema>;
type FormOutput = z.output<typeof FormSchema>; // Same as z.infer

// input: FormInput, output: FormOutput
const formMethods = useForm({ resolver: zodResolver(FormSchema) });

In this case, the form鈥檚 input type is FormInput, and the submitted data type should be FormOutput.

@aspirisen aspirisen added publish-next Publish next package version and removed publish-next Publish next package version labels Sep 30, 2025
@aspirisen
aspirisen merged commit 6edb29d into react-hook-form:main Sep 30, 2025
7 of 9 checks passed
@aspirisen

Copy link
Copy Markdown
Collaborator

@SeokminHong thank you for the fix

@github-actions

Copy link
Copy Markdown

馃帀 This PR is included in version 0.8.3 馃帀

The release is available on:

Your semantic-release bot 馃摝馃殌

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

About transformed values support

2 participants