fix(form-core): fix DeepValue from record values being wrong
Closes #1551
This PR fixes a wrong intersection that occurs when iterating over template strings (such as records). The issue arose because of TypeScript inferring the following:
type DeepKeysExample = 'records' | `records.${string}` | `records.${string}.name`
type GetValueFrom = 'records.foo.name'
// This matches both `records.${string}.name` as well as `records.${string}`.
// Generated DeepValue:
// { name: string } & string
// With PR fix:
// string
[!IMPORTANT] TypeScript has a limitation with template string types. Nested records are not yet safe. Example below:
type NestedRecord = {
numberRecord: Record<string, number>
objectRecord: Record<string, { age: number }>
}
type RecordWrapper = {
records: Record<string, NestedRecord>
}
type Test1 = DeepValue<RecordWrapper, 'records.foo.numberRecord.bar'>
// Type: NestedRecord & number
// `records.${'foo'}.numberRecord.${'bar'}`
// `records.${'foo.numberRecord.bar'}`
type Test2 = DeepValue<RecordWrapper, 'records.foo.objectRecord.bar'>
// Type: NestedRecord & { age: number }
// `records.${'foo'}.objectRecord.${'bar'}`
// `records.${'foo.objectRecord.bar'}`
type Test3 = DeepValue<RecordWrapper, 'records.foo.objectRecord.bar.age'>
// Type: number
// `records.${'foo'}.objectRecord.${'bar'}.age`
View your CI Pipeline Execution ↗ for commit da26a5ca14eb244851ca333a88f6facc0ac06941
| Command | Status | Duration | Result |
|---|---|---|---|
nx affected --targets=test:sherif,test:knip,tes... |
✅ Succeeded | 1m 16s | View ↗ |
nx run-many --target=build --exclude=examples/** |
✅ Succeeded | 26s | View ↗ |
☁️ Nx Cloud last updated this comment at 2025-11-11 07:55:45 UTC
More templates
- @tanstack/form-example-angular-array
- @tanstack/form-example-angular-large-form
- @tanstack/form-example-angular-simple
- @tanstack/form-example-angular-standard-schema
- @tanstack/form-example-lit-array
- @tanstack/form-example-lit-simple
- @tanstack/form-example-lit-standard-schema
- @tanstack/form-example-lit-ui-libraries
- @tanstack/form-example-solid-array
- @tanstack/form-example-solid-large-form
- @tanstack/form-example-solid-simple
- @tanstack/form-example-solid-standard-schema
- @tanstack/form-example-react-array
- @tanstack/form-example-react-compiler
- @tanstack/form-example-react-devtools
- @tanstack/form-example-react-dynamic
- @tanstack/field-errors-from-form-validators
- @tanstack/form-example-react-large-form
- @tanstack/form-example-react-next-server-actions
- @tanstack/form-example-react-query-integration
- @tanstack/form-example-remix
- @tanstack/form-example-react-simple
- @tanstack/form-example-react-standard-schema
- @tanstack/form-example-react-tanstack-start
- @tanstack/form-example-react-ui-libraries
- @tanstack/form-example-svelte-array
- @tanstack/form-example-svelte-simple
- @tanstack/form-example-svelte-standard-schema
- @tanstack/form-example-vue-array
- @tanstack/form-example-vue-simple
- @tanstack/form-example-vue-standard-schema
@tanstack/angular-form
npm i https://pkg.pr.new/@tanstack/angular-form@1558
@tanstack/form-core
npm i https://pkg.pr.new/@tanstack/form-core@1558
@tanstack/form-devtools
npm i https://pkg.pr.new/@tanstack/form-devtools@1558
@tanstack/lit-form
npm i https://pkg.pr.new/@tanstack/lit-form@1558
@tanstack/react-form
npm i https://pkg.pr.new/@tanstack/react-form@1558
@tanstack/react-form-devtools
npm i https://pkg.pr.new/@tanstack/react-form-devtools@1558
@tanstack/solid-form
npm i https://pkg.pr.new/@tanstack/solid-form@1558
@tanstack/svelte-form
npm i https://pkg.pr.new/@tanstack/svelte-form@1558
@tanstack/vue-form
npm i https://pkg.pr.new/@tanstack/vue-form@1558
commit: da26a5c
Codecov Report
:white_check_mark: All modified and coverable lines are covered by tests.
:white_check_mark: Project coverage is 90.53%. Comparing base (6892ed0) to head (da26a5c).
:warning: Report is 47 commits behind head on main.
Additional details and impacted files
@@ Coverage Diff @@
## main #1558 +/- ##
==========================================
+ Coverage 90.35% 90.53% +0.18%
==========================================
Files 38 38
Lines 1752 1807 +55
Branches 444 466 +22
==========================================
+ Hits 1583 1636 +53
- Misses 149 151 +2
Partials 20 20
:umbrella: View full report in Codecov by Sentry.
:loudspeaker: Have feedback on the report? Share it here.
:rocket: New features to boost your workflow:
- :snowflake: Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
- :package: JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.
thank you for fixing this! is there a timeline on when it will be included in a release? 👀
@binajmen Well, the main issue is that this isn't really a fix. This PR has been a bit stale because of that ... but I'm not sure there will be a convenient solution that doesn't need reworking all of the DeepKeys types
I made progress! It now shows possible values as union instead of an intersection. Will commit the changes tomorrow.
🦋 Changeset detected
Latest commit: da26a5ca14eb244851ca333a88f6facc0ac06941
The changes in this PR will be included in the next version bump.
This PR includes changesets to release 9 packages
| Name | Type |
|---|---|
| @tanstack/form-core | Patch |
| @tanstack/react-form | Patch |
| @tanstack/angular-form | Patch |
| @tanstack/form-devtools | Patch |
| @tanstack/lit-form | Patch |
| @tanstack/solid-form | Patch |
| @tanstack/svelte-form | Patch |
| @tanstack/vue-form | Patch |
| @tanstack/react-form-devtools | Patch |
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