fix(form-core): fix DeepValue from record values being wrong #1558
main fromdeepvalue-records-fix·opened 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`- 1
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-devtools
- @tanstack/form-example-solid-large-form
- @tanstack/form-example-solid-simple
- @tanstack/form-example-solid-standard-schema
- @tanstack/form-example-svelte-array
- @tanstack/form-example-svelte-large-form
- @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/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-next-server-actions-zod
- @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/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/react-form-nextjs
npm i https://pkg.pr.new/@tanstack/react-form-nextjs@1558@tanstack/react-form-remix
npm i https://pkg.pr.new/@tanstack/react-form-remix@1558@tanstack/react-form-start
npm i https://pkg.pr.new/@tanstack/react-form-start@1558@tanstack/solid-form
npm i https://pkg.pr.new/@tanstack/solid-form@1558@tanstack/solid-form-devtools
npm i https://pkg.pr.new/@tanstack/solid-form-devtools@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@1558commit:
83f3c34Codecov Report#
:white_check_mark: All modified and coverable lines are covered by tests. :white_check_mark: Project coverage is 89.93%. Comparing base (
6892ed0) to head (83f3c34). :warning: Report is 141 commits behind head on main.Additional details and impacted files
@@ Coverage Diff @@ ## main #1558 +/- ## ========================================== - Coverage 90.35% 89.93% -0.43% ========================================== Files 38 49 +11 Lines 1752 2006 +254 Branches 444 507 +63 ========================================== + Hits 1583 1804 +221 - Misses 149 181 +32 - Partials 20 21 +1: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: 83f3c34c4b1880f988a856b9a596e34b4494f5da
The changes in this PR will be included in the next version bump.
This PR includes changesets to release 13 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-nextjs Patch @tanstack/react-form-remix Patch @tanstack/react-form-start Patch @tanstack/react-form-devtools Patch @tanstack/solid-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
it's green! what is blocking the merge?!
Please don't.
LeCarbonator(GitHub profile, opens in a new tab) linked this to fix #1551
Sign in to join this conversation.
View your CI Pipeline Execution ↗ for commit 83f3c34c4b1880f988a856b9a596e34b4494f5da
nx affected --targets=test:sherif,test:knip,tes...nx run-many --target=build --exclude=examples/**☁️ Nx Cloud last updated this comment at
2026-02-24 18:24:23UTC