Skip to content

Conversation

@LeCarbonator
Copy link
Contributor

@LeCarbonator LeCarbonator commented Jun 5, 2025

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`

@nx-cloud
Copy link

nx-cloud bot commented Jun 5, 2025

View your CI Pipeline Execution ↗ for commit d586448

Command Status Duration Result
nx affected --targets=test:sherif,test:knip,tes... ✅ Succeeded 1m 24s View ↗
nx run-many --target=build --exclude=examples/** ✅ Succeeded 26s View ↗

☁️ Nx Cloud last updated this comment at 2025-11-07 22:50:41 UTC

@pkg-pr-new
Copy link

pkg-pr-new bot commented Jun 5, 2025

More templates

@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: d586448

@codecov
Copy link

codecov bot commented Jun 5, 2025

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 90.53%. Comparing base (6892ed0) to head (d586448).
⚠️ 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              

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@LeCarbonator LeCarbonator marked this pull request as ready for review June 8, 2025 11:50
@binajmen
Copy link

binajmen commented Aug 5, 2025

thank you for fixing this! is there a timeline on when it will be included in a release? 👀

@LeCarbonator
Copy link
Contributor Author

@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

@LeCarbonator
Copy link
Contributor Author

I made progress! It now shows possible values as union instead of an intersection. Will commit the changes tomorrow.

@changeset-bot
Copy link

changeset-bot bot commented Nov 6, 2025

⚠️ No Changeset found

Latest commit: d586448

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Click here to learn what changesets are, and how to add one.

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

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.

Records fields have wrong types

3 participants