Skip to content

fix(types): preserve undefined in nested array element values - #13995

Merged
bluebill1049 merged 3 commits into
react-hook-form:masterfrom
wozhenbang2004:patch-2
Nov 6, 2026
Merged

bluebill1049 merged 3 commits into
react-hook-form:masterfrom
wozhenbang2004:patch-2

Conversation

@wozhenbang2004

Copy link
Copy Markdown
Contributor

Proposed Changes

For rows: ({ name: string } | undefined)[], getValues("rows.0.name") is inferred as string, although the selected row can be undefined. The recursive array branch drops the explicit undefined element type.

Preserve it for ordinary and readonly arrays. Keep fixed and variadic tuple inference unchanged. Add type regressions for nested paths, leaf unions, tuple controls, and the public getValues result. The four affected assertions fail against the original implementation.

Validation with Node 22:

  • 133 suites, 1,832 unit tests and 26 snapshots passed.
  • All 90 existing Chromium E2E tests passed with one worker and no retries, using a local browser/server configuration. Test files and assertions are unchanged.
  • pnpm type, pnpm test:type, lint, Prettier, builds, and both API Extractor checks passed. No added lint warnings; the API report is unchanged.

Type of change

  • Bug fix

Checklist:

  • My code follows the style guidelines of this project
  • I have performed a self-review of my own code
  • My changes generate no new warnings
  • I have added tests that prove my fix is effective or that my feature works
  • New and existing tests pass locally with my changes

Refactor type handling for array keys in PathValueImpl.
Cover ordinary and readonly arrays with explicit undefined elements, nested paths and leaf unions. Keep tuple and variadic rest inference unchanged.
Assert the public getValues return type for an array whose elements may be undefined.
@bluebill1049
bluebill1049 merged commit 7638c08 into react-hook-form:master Nov 6, 2026
6 checks passed
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.

2 participants