Skip to content

fix(lit-query): add DataTag to the queryKey returned by infiniteQueryOptions - #11146

Open
lazerg wants to merge 1 commit into
TanStack:mainfrom
lazerg:fix/issue-11142-lit-infinite-query-options-datatag
Open

fix(lit-query): add DataTag to the queryKey returned by infiniteQueryOptions#11146
lazerg wants to merge 1 commit into
TanStack:mainfrom
lazerg:fix/issue-11142-lit-infinite-query-options-datatag

Conversation

@lazerg

@lazerg lazerg commented Aug 6, 2026

Copy link
Copy Markdown

🎯 Changes

infiniteQueryOptions in lit-query returns the options unchanged, without the DataTag brand its own queryOptions already applies. The queryKey carries no data type, so client.getQueryData(opts.queryKey) and setQueryData fall back to unknown and the updater argument can't be used.

The return type now intersects queryKey: DataTag<TQueryKey, InfiniteData<TQueryFnData>, TError>, mirroring queryOptions.ts here and infiniteQueryOptions in react-query. Added a case to type-inference.test.ts next to the existing queryOptions one.

Fixes #11142

✅ Checklist

  • I have followed the steps in the Contributing guide.
  • I have tested this code locally with pnpm run test:pr.

Local verification detail: vitest run and test:types on lit-query, 102 tests passed, no type errors. The new assertions fail on main, where getQueryData resolves to unknown.

🚀 Release Impact

  • This change affects published code, and I have generated a changeset.
  • This change is docs/CI/dev-only (no release).

@coderabbitai

coderabbitai Bot commented Aug 6, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

📝 Walkthrough

Walkthrough

infiniteQueryOptions now brands its query key with DataTag, preserving InfiniteData and error types for cache APIs. Type-inference tests cover cached reads and updates, and a patch changeset documents the change.

Changes

Infinite query type inference

Layer / File(s) Summary
DataTag return contract
packages/lit-query/src/infiniteQueryOptions.ts
infiniteQueryOptions now returns a branded queryKey with InfiniteData<TQueryFnData> and TError. Its implementation signature accepts unknown.
Inference coverage
packages/lit-query/src/tests/type-inference.test.ts, .changeset/wise-doors-shout.md
Tests verify InfiniteData inference for tagged keys, getQueryData, and setQueryData. The changeset documents the patch.

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

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Linked Issues check ✅ Passed The implementation and type-inference tests satisfy issue #11142 by adding DataTag and restoring InfiniteData and error-type inference.
Out of Scope Changes check ✅ Passed All changes support issue #11142 and the stated objectives, including the implementation, type test, and release changeset.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Title check ✅ Passed The title clearly and concisely describes the primary change to add DataTag to the queryKey returned by infiniteQueryOptions.
Description check ✅ Passed The description explains the change and motivation, completes the checklist, documents testing, and confirms the changeset.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

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

Comment @coderabbitai help to get the list of available commands.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🧹 Nitpick comments (1)
packages/lit-query/src/tests/type-inference.test.ts (1)

211-230: 🎯 Functional Correctness | 🔵 Trivial | ⚡ Quick win

Cover the error brand and callback updater.

The assertions at Line 217 through Line 219 check only dataTagSymbol. They do not check dataTagErrorSymbol, although the return type carries TError. The value-form setQueryData call also does not verify the callback updater parameter. Add an explicit error type, assert dataTagErrorSymbol, and add a callback-form setQueryData assertion.

Based on the PR objective and the DataTag definition in packages/query-core/src/types.ts, this test should cover both brands and the updater path.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@packages/lit-query/src/tests/type-inference.test.ts` around lines 211 - 230,
Update the infiniteQueryOptions type-inference test to provide an explicit error
type, assert infiniteQueryOpts.queryKey[dataTagErrorSymbol] resolves to that
error type, and add a callback-form client.setQueryData assertion that verifies
the updater receives InfiniteData<{ page: number }> | undefined and returns the
expected data type. Preserve the existing dataTagSymbol and value-form
assertions.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Nitpick comments:
In `@packages/lit-query/src/tests/type-inference.test.ts`:
- Around line 211-230: Update the infiniteQueryOptions type-inference test to
provide an explicit error type, assert
infiniteQueryOpts.queryKey[dataTagErrorSymbol] resolves to that error type, and
add a callback-form client.setQueryData assertion that verifies the updater
receives InfiniteData<{ page: number }> | undefined and returns the expected
data type. Preserve the existing dataTagSymbol and value-form assertions.

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro Plus

Run ID: 7a0cc58d-9d78-423f-9721-bccbbad7b874

📥 Commits

Reviewing files that changed from the base of the PR and between 46d7f02 and 85ba82c.

📒 Files selected for processing (3)
  • .changeset/wise-doors-shout.md
  • packages/lit-query/src/infiniteQueryOptions.ts
  • packages/lit-query/src/tests/type-inference.test.ts

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.

[lit-query] infiniteQueryOptions does not have DataTag on queryKey

1 participant