Skip to content
Source
Sign inSign up
TanStack/form

fix(form-core): preserve FieldWithValue name string type #2466

OpenPriyeshshrivastav(GitHub profile, opens in a new tab)wants to merge 1 commit intoalpha fromrefs/pull/2466/headopened

Summary

Fixes #2465.

  • Change the first generic parameter of FieldWithValue<TFieldValue> from any to string.
  • Preserve the existing value and handleChange type safety.
  • Add a TypeScript regression test verifying that field.name is typed as string and rejects invalid numeric operations.

Validation

  • TypeScript regression test passed
  • Form-core type tests passed
  • Form-core build passed
  • ESLint completed successfully

Summary by CodeRabbit

  • Bug Fixes
    • Corrected field name typing to preserve string types while retaining the field’s value type.
    1. 🦋 Changeset detected

      Latest commit: 4a15109fbdf585922cffe5ca89eea8f65365ae8a

      The changes in this PR will be included in the next version bump.

      This PR includes changesets to release 13 packages
      NameType
      @tanstack/form-corePatch
      @tanstack/angular-formPatch
      @tanstack/form-devtoolsPatch
      @tanstack/lit-formPatch
      @tanstack/preact-formPatch
      @tanstack/react-form-nextjsPatch
      @tanstack/react-form-startPatch
      @tanstack/react-formPatch
      @tanstack/solid-formPatch
      @tanstack/svelte-formPatch
      @tanstack/vue-formPatch
      @tanstack/react-form-devtoolsPatch
      @tanstack/solid-form-devtoolsPatch

      Not sure what this means? Click here to learn what changesets are.

      Click here if you're a maintainer who wants to add another changeset to this PR

    2. coderabbitai[bot](GitHub profile, opens in a new tab)commented
      Explain Change →

      No actionable comments were generated in the recent review.

      Walkthrough

      FieldWithValue<TFieldValue> now types name as string instead of any. Type tests check the name and value types, invalid name operations, and accepted and rejected handleChange arguments. A changeset declares a patch release for @tanstack/form-core.

      Changes: FieldWithValue name typing

      Layer / File(s)Summary
      Update and verify FieldWithValue typing
      packages/form-core/src/types.public.ts, packages/form-core/tests/FieldWithValue.test-d.ts, .changeset/dark-suits-itch.md
      FieldWithValue now uses string for the FieldApi name type argument. Type assertions check name, value, and handleChange. A changeset declares a patch release.

      Estimated code review effort: 2 (Simple) | ~8 minutes

      Change: Bug fix · Severity of issue fixed: Low

      Possibly related PRs

      • TanStack/form#2448: Refactors public FieldApi and form-core generic contracts used by the FieldWithValue alias.
      • TanStack/form#2450: Adds a Vue StringField that accepts FieldWithValue<string> and reads field.name.

      Suggested reviewers: lecarbonator

      Merge Risk: Minimal · up to 4a151

      No merge-blocking risk is established for this narrowly scoped typing change.

      Pre-merge checks: Passed 5

      Check nameStatusExplanation
      Title checkPassedThe title names the main change: the first generic argument of FieldWithValue's FieldApi is changed so the field name is typed as string. The title uses the conventional fix(form-core) prefix and sits…
      Description checkPassedThe description follows the template's main sections. It has a Summary that states the change, the reason (linked issue #2465), the type-test addition, and validation results. It does not include the …
      Linked Issues checkPassedObjective [#2465]: FieldWithValue<T>['name'] must be string, not any. The value and update types must stay T, and the alias must still accept fields at arbitrary paths.

      Evidence at head: `pac…
      Out of Scope Changes checkPassedThe PR changes three files, and each one connects to #2465.

      - packages/form-core/src/types.public.ts: one-line change of the FieldWithValue name argument from any to string. This is the core …
      Docstring CoveragePassedNo eligible functions found in the changed files. Skipping docstring coverage check. Docstring coverage is scoped to functions touched by this diff with cyclomatic complexity of at least 2. Documentat…
      Full details: Title check

      Explanation

      The title names the main change: the first generic argument of FieldWithValue's FieldApi is changed so the field name is typed as string. The title uses the conventional fix(form-core) prefix and sits within the 56-character length. It matches the changeset, the type alias edit, and the new type test.

      Full details: Description check

      Explanation

      The description follows the template's main sections. It has a Summary that states the change, the reason (linked issue #2465), the type-test addition, and validation results. It does not include the template's Checklist or Release Impact sections. The author does not tick the changeset item, though the raw summary shows that a changeset file was added. The description omits the template's checklist and release-impact sections and lacks a contributing-guide confirmation, so it is mostly complete rather than fully complete.

      Resolution

      Add the template's Checklist and Release Impact sections. Mark the changeset item as done, because the PR adds .changeset/dark-suits-itch.md. Confirm the contributing-guide and AI-assistance items.

      Full details: Linked Issues check

      Explanation

      Objective [#2465]: FieldWithValue&lt;T&gt;['name'] must be string, not any. The value and update types must stay T, and the alias must still accept fields at arbitrary paths.

      Evidence at head: packages/form-core/src/types.public.ts changes the first FieldApi argument of FieldWithValue&lt;TFieldValue&gt; from any to string. This matches the direction proposed in #2465. The other type arguments are unchanged, so TFieldValue still drives value and handleChange.

      Evidence at head: packages/form-core/tests/FieldWithValue.test-d.ts asserts field.name equals string, asserts field.value equals boolean for FieldWithValue&lt;boolean&gt;, and expects errors for const invalidName: number = field.name, field.name.toFixed(), and field.handleChange('not a boolean'). These cover the name type, the invalid numeric operations, and the value/update typing.

      Arbitrary-path acceptance: the PR test does not assign a concrete-path field to FieldWithValue&lt;boolean&gt;. The #2465 reporter tested the same alias with a concrete render-prop field and with fieldComponent.strict and fieldComponent.loose, and reported acceptance. The change only modifies the name argument, and TName is exposed through a getter, so this result is supported by the reported evidence. This PR does not add its own test for it. No coding requirement is unmet.

      Full details: Out of Scope Changes check

      Explanation

      The PR changes three files, and each one connects to #2465.

      • packages/form-core/src/types.public.ts: one-line change of the FieldWithValue name argument from any to string. This is the core fix.
      • packages/form-core/tests/FieldWithValue.test-d.ts: new type regression test for the name, value, and handleChange requirements in #2465.
      • .changeset/dark-suits-itch.md: patch changeset for @tanstack/form-core. This is release metadata for the same fix and does not add behavior.

      No unrelated code, refactoring, or API change appears in the summary or in the reviewed diff.

      Full details: Docstring Coverage

      Explanation

      No eligible functions found in the changed files. Skipping docstring coverage check. Docstring coverage is scoped to functions touched by this diff with cyclomatic complexity of at least 2. Documentation-only edits and deletions within surviving functions are included; unchanged diff context and fully deleted functions are excluded. Analyzed 0 functions across 2 files. (1 skipped: 1 unsupported.)

      Finishing Touches

      Generate unit tests (beta)

      • Create a new PR
      • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

      Tip

      🎯 Customize your risk assessments

      Guide how CodeRabbit assesses merge risk and security architecture risk. Highlight sensitive changes and explain your security boundaries using Merge Risk Instructions and Security Risk Instructions in your review settings. Security architecture risk assessments require the Advanced plan or above.

      ✅ Automatic approvals, with your rules

      Let CodeRabbit approve pull requests once required threads are resolved, pre-merge checks pass, and your risk limits are met. Enable Automatic approvals in review settings, with overrides for teams or file paths.

      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

      Recent review info

      Run configuration

      Commits

      Reviewing files that changed from the base of the PR and between 2b4fc5c6f243669359b67643807713970fd7014d and 4a15109fbdf585922cffe5ca89eea8f65365ae8a.

      Files selected for processing: 3

      • .changeset/dark-suits-itch.md
      • packages/form-core/src/types.public.ts
      • packages/form-core/tests/FieldWithValue.test-d.ts

      Included review availability: This review used your included allowance. Your plan provides up to 8 included reviews per hour; 7 remain after this review.

    3. Hi @pedro757, I've opened PR #2466 addressing this issue. It includes the type fix and a regression test. Thanks for allowing me to work on this!

Sign in to join this conversation.