Skip to content

fix(types): correct PathValueImpl type inference#13150

Merged
bluebill1049 merged 1 commit intoreact-hook-form:masterfrom
joseph0926:fix/fix-pathvalueimpl-type
Nov 18, 2025
Merged

fix(types): correct PathValueImpl type inference#13150
bluebill1049 merged 1 commit intoreact-hook-form:masterfrom
joseph0926:fix/fix-pathvalueimpl-type

Conversation

@joseph0926
Copy link
Copy Markdown
Contributor

Problem

In v7.64.0, commit 8d61561 changed PathValueImpl to support optional array fields,
However, the condition undefined extends T is too broad and interferes with TypeScript’s reverse type inference, so in some cases the inferred type ends up as never

ex)

const { field } = useController({ name: 'items', defaultValue: [] });
// error: Type 'string' is not assignable to type 'never'

Solution

// src/types/path/eager.ts

- : undefined extends T
+ : T extends undefined

This keeps the support for optional array fields introduced in PR #13057while restoring correct type inference.

Testing

  • All existing tests continue to pass
  • Added a type test for this issue in src/__typetest__/useController.test-d.ts

Related Issues

Fixes #13081
Related to PR #13057

@bluebill1049 bluebill1049 merged commit a42f198 into react-hook-form:master Nov 18, 2025
6 checks passed
@joseph0926 joseph0926 deleted the fix/fix-pathvalueimpl-type branch November 18, 2025 07:10
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.

issue: useController causing type error from 7.63.0 -> 7.64.0

2 participants