Skip to content

Conversation

@ntatoud
Copy link
Member

@ntatoud ntatoud commented Nov 12, 2025

When using React Hook Form with a zodResolver that has a transform clause (i.e output type != input type)
The types where not properly infered on the FormFieldController and Form component.

I know it's a bit annoying to have to pass the extra generic.
Dunno if it's worth the struggle :/

Summary by CodeRabbit

  • Refactor
    • Enhanced type system definitions across all form field components including text, select, date, number, checkbox, radio, and OTP fields.
    • Updated form field controller and root form component for improved type consistency and compatibility throughout the form system.

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Nov 12, 2025

Walkthrough

This PR adds a new generic type parameter TTransformedValues (defaulting to TFieldValues) across all form field components, their props, and the form field controller. The parameter is propagated through the FieldProps interface and threaded consistently through the public API without modifying runtime behavior.

Changes

Cohort / File(s) Summary
Field Components
src/components/form/field-checkbox/index.tsx, src/components/form/field-checkbox-group/index.tsx, src/components/form/field-date/index.tsx, src/components/form/field-number/index.tsx, src/components/form/field-otp/index.tsx, src/components/form/field-radio-group/index.tsx, src/components/form/field-select/index.tsx, src/components/form/field-text/index.tsx
Added TTransformedValues generic parameter to all field component props types and component signatures, defaulting to TFieldValues. Updated props typings to pass TTransformedValues through to underlying FieldProps.
Form Field Controller
src/components/form/form-field-controller.tsx
Extended FieldCustomProps, FieldProps, FormFieldControllerProps, FormFieldController component, and FormFieldControllerContextValue to accept and propagate TTransformedValues generic parameter across all field-related types and controller props union.
Form Component
src/components/form/form.tsx
Added TContext and TTransformedValues generic parameters to FormProps type. Updated FormProviderProps usage to include new generics in both union branches. Changed onSubmit type from SubmitHandler<TFieldValues> to SubmitHandler<TTransformedValues>.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

  • form-field-controller.tsx: Central coordination file with high complexity—carefully verify that all field prop unions correctly include TTransformedValues and that type parameter propagation is consistent across all field types.
  • Field components (8 files): Verify the pattern is applied uniformly and that generic defaults are consistent across all field types.
  • form.tsx: Ensure onSubmit handler type change (SubmitHandler<TTransformedValues>) aligns with intended behavior and doesn't break existing call sites.

Possibly related PRs

Suggested labels

enhancement, components

Suggested reviewers

  • yoannfleurydev
  • ivan-dalmet

Pre-merge checks and finishing touches

✅ Passed checks (3 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title directly addresses the main change: adding proper type inference for form fields when using a resolver with a transform, which is the core focus of all file modifications.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch fix/form-fields-typing

📜 Recent review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between cb6585c and 9780b04.

📒 Files selected for processing (10)
  • src/components/form/field-checkbox-group/index.tsx (2 hunks)
  • src/components/form/field-checkbox/index.tsx (2 hunks)
  • src/components/form/field-date/index.tsx (2 hunks)
  • src/components/form/field-number/index.tsx (2 hunks)
  • src/components/form/field-otp/index.tsx (2 hunks)
  • src/components/form/field-radio-group/index.tsx (2 hunks)
  • src/components/form/field-select/index.tsx (2 hunks)
  • src/components/form/field-text/index.tsx (2 hunks)
  • src/components/form/form-field-controller.tsx (3 hunks)
  • src/components/form/form.tsx (1 hunks)
🧰 Additional context used
🧬 Code graph analysis (10)
src/components/form/field-checkbox/index.tsx (1)
src/components/form/form-field-controller.tsx (1)
  • FieldProps (43-54)
src/components/form/form.tsx (5)
src/components/form/field-text/docs.stories.tsx (3)
  • form (84-112)
  • form (55-82)
  • form (31-53)
src/components/form/form-test-utils.tsx (2)
  • T (14-41)
  • values (34-34)
src/components/form/docs.stories.tsx (2)
  • form (70-114)
  • form (30-68)
src/components/form/field-radio-group/docs.stories.tsx (1)
  • form (65-92)
src/components/form/field-number/docs.stories.tsx (1)
  • form (31-53)
src/components/form/field-radio-group/index.tsx (1)
src/components/form/form-field-controller.tsx (1)
  • FieldProps (43-54)
src/components/form/field-text/index.tsx (1)
src/components/form/form-field-controller.tsx (1)
  • FieldProps (43-54)
src/components/form/field-number/index.tsx (1)
src/components/form/form-field-controller.tsx (1)
  • FieldProps (43-54)
src/components/form/field-date/index.tsx (1)
src/components/form/form-field-controller.tsx (1)
  • FieldProps (43-54)
src/components/form/form-field-controller.tsx (9)
src/components/form/field-number/index.tsx (1)
  • FieldNumberProps (13-26)
src/components/form/field-select/index.tsx (1)
  • FieldSelectProps (11-23)
src/components/form/field-date/index.tsx (1)
  • FieldDateProps (11-23)
src/components/form/field-text/index.tsx (1)
  • FieldTextProps (12-24)
src/components/form/field-otp/index.tsx (1)
  • FieldOtpProps (16-29)
src/components/form/field-radio-group/index.tsx (1)
  • FieldRadioGroupProps (15-29)
src/components/form/field-checkbox/index.tsx (1)
  • FieldCheckboxProps (11-23)
src/components/form/field-checkbox-group/index.tsx (1)
  • FieldCheckboxGroupProps (17-30)
src/components/form/form-field-error.tsx (1)
  • TFieldValues (33-93)
src/components/form/field-checkbox-group/index.tsx (1)
src/components/form/form-field-controller.tsx (1)
  • FieldProps (43-54)
src/components/form/field-select/index.tsx (1)
src/components/form/form-field-controller.tsx (1)
  • FieldProps (43-54)
src/components/form/field-otp/index.tsx (1)
src/components/form/form-field-controller.tsx (1)
  • FieldProps (43-54)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (2)
  • GitHub Check: Playwright E2E Tests
  • GitHub Check: 🔬 Tests (22)
🔇 Additional comments (8)
src/components/form/field-checkbox-group/index.tsx (1)

17-37: LGTM! Type-level enhancement for transformed values.

The addition of TTransformedValues generic parameter is correctly implemented:

  • Defaults to TFieldValues for backward compatibility
  • Properly threaded through FieldProps
  • Component signature consistently updated
  • No runtime behavior changes

This aligns with the PR objective to properly infer types when using React Hook Form resolvers with transforms (e.g., Zod's .transform()).

src/components/form/field-date/index.tsx (1)

11-30: LGTM! Consistent type enhancement.

The TTransformedValues generic is correctly propagated through FieldDateProps and the FieldDate component, following the same pattern as other field components in this PR.

src/components/form/field-checkbox/index.tsx (1)

11-30: LGTM! Type definitions correctly updated.

The TTransformedValues generic parameter is properly added to both FieldCheckboxProps and FieldCheckbox, maintaining consistency with the broader type system changes.

src/components/form/field-number/index.tsx (1)

13-33: LGTM! Types correctly extended.

The TTransformedValues generic is properly integrated into FieldNumberProps and the FieldNumber component signature, following the established pattern.

src/components/form/field-radio-group/index.tsx (1)

15-36: LGTM! Type system enhancement applied correctly.

The TTransformedValues generic parameter is consistently added to FieldRadioGroupProps and the FieldRadioGroup component, maintaining the pattern across all field components.

src/components/form/field-select/index.tsx (1)

11-30: LGTM! Generic parameter correctly propagated.

The TTransformedValues type parameter is properly threaded through FieldSelectProps and the FieldSelect component, consistent with other field components in this PR.

src/components/form/field-text/index.tsx (1)

12-31: LGTM! Type definitions updated consistently.

The TTransformedValues generic is correctly added to FieldTextProps and the FieldText component, following the same pattern as all other field components.

src/components/form/field-otp/index.tsx (1)

16-36: LGTM! Type enhancement consistently applied.

The TTransformedValues generic parameter is properly integrated into FieldOtpProps and the FieldOtp component, completing the consistent type system enhancement across all field components.


Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@sonarqubecloud
Copy link

@DecampsRenan DecampsRenan merged commit 7b12d92 into main Nov 12, 2025
12 of 13 checks passed
@DecampsRenan DecampsRenan deleted the fix/form-fields-typing branch November 12, 2025 13:58
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.

3 participants