fix(form-core): preserve FieldWithValue name string type #2466
alpha fromrefs/pull/2466/head·opened Summary#
Fixes #2465.
- Change the first generic parameter of
FieldWithValue<TFieldValue>fromanytostring. - Preserve the existing value and handleChange type safety.
- Add a TypeScript regression test verifying that
field.nameis typed asstringand 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
No actionable comments were generated in the recent review.
Walkthrough
-
FieldWithValue<TFieldValue>now typesnameasstringinstead ofany. Type tests check the name and value types, invalid name operations, and accepted and rejectedhandleChangearguments. 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.mdFieldWithValuenow usesstringfor theFieldApiname type argument. Type assertions checkname,value, andhandleChange. 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
FieldApiand form-core generic contracts used by theFieldWithValuealias. - TanStack/form#2450: Adds a Vue
StringFieldthat acceptsFieldWithValue<string>and readsfield.name.
Suggested reviewers:
lecarbonator - TanStack/form#2448: Refactors public
Merge Risk:
Minimal · up to4a151-
No merge-blocking risk is established for this narrowly scoped typing change.
Pre-merge checks:
5-
Check name Status Explanation Title check 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… Description check 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 …Linked Issues check Objective [ #2465]:FieldWithValue<T>['name']must bestring, notany. The value and update types must stayT, and the alias must still accept fields at arbitrary paths.
Evidence at head: `pac…Out of Scope Changes check The PR changes three files, and each one connects to #2465.
-packages/form-core/src/types.public.ts: one-line change of theFieldWithValuename argument fromanytostring. This is the core …Docstring Coverage 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. 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<T>['name']must bestring, notany. The value and update types must stayT, and the alias must still accept fields at arbitrary paths.Evidence at head:
packages/form-core/src/types.public.tschanges the firstFieldApiargument ofFieldWithValue<TFieldValue>fromanytostring. This matches the direction proposed in#2465. The other type arguments are unchanged, soTFieldValuestill drivesvalueandhandleChange.Evidence at head:
packages/form-core/tests/FieldWithValue.test-d.tsassertsfield.nameequalsstring, assertsfield.valueequalsbooleanforFieldWithValue<boolean>, and expects errors forconst invalidName: number = field.name,field.name.toFixed(), andfield.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<boolean>. The#2465reporter tested the same alias with a concrete render-prop field and withfieldComponent.strictandfieldComponent.loose, and reported acceptance. The change only modifies the name argument, andTNameis 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 theFieldWithValuename argument fromanytostring. 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.
Recent review info-
Run configuration-
- Source mode: Auto
- Repository: TanStack/form
- Branch: alpha
- File: .coderabbit.yaml
- Commit: 2b4fc5c
- Layers: Repository YAML
- Review profile: CHILL
- Plan: Advanced
- Run ID:
a8426b16-7977-4c87-9ae3-58805357e1ff
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.mdpackages/form-core/src/types.public.tspackages/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.
-
-
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!
Priyeshshrivastav(GitHub profile, opens in a new tab) linked this to fix #2465
Sign in to join this conversation.
🦋 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
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