Skip to content

fix(query-core): infer setQueriesData data type from query filters#10834

Open
raashish1601 wants to merge 1 commit into
TanStack:mainfrom
raashish1601:fix/query-client-setqueriesdata-types
Open

fix(query-core): infer setQueriesData data type from query filters#10834
raashish1601 wants to merge 1 commit into
TanStack:mainfrom
raashish1601:fix/query-client-setqueriesdata-types

Conversation

@raashish1601
Copy link
Copy Markdown
Contributor

@raashish1601 raashish1601 commented May 30, 2026

Summary

Fix QueryClient.setQueriesData typing so filtered-query overloads infer cached data types from tagged query keys when queryKey is provided in filters.

Changes

  • Add QueryDataForFilters helper in queryClient for InferDataFromTag over QueryFilters.
  • Add a dedicated overload for setQueriesData using that helper.
  • Update queryClient type tests by removing the outdated TODO and asserting inferred return type.

Validation

  • corepack pnpm exec tsc -p tsconfig.legacy.json --pretty false --noEmit (packages/query-core)
  • corepack pnpm exec vitest run src/tests/queryClient.test-d.tsx

Summary by CodeRabbit

  • Tests

    • Updated type-level assertions for setQueriesData validation
  • Improvements

    • Enhanced type inference for the setQueriesData method to provide more accurate data type information based on query filters

Review Change Stack

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented May 30, 2026

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 97f9cca5-29fc-476b-9610-d5d9e3dafe9d

📥 Commits

Reviewing files that changed from the base of the PR and between 7fa2781 and 1ab0afa.

📒 Files selected for processing (2)
  • packages/query-core/src/__tests__/queryClient.test-d.tsx
  • packages/query-core/src/queryClient.ts

📝 Walkthrough

Walkthrough

This PR introduces a QueryDataForFilters conditional type to the QueryClient and updates the setQueriesData method's type overloads to infer data types from query filters rather than solely from the generic TQueryFnData parameter, with corresponding type test updates validating the improved inference behavior.

Changes

setQueriesData Type Inference with QueryDataForFilters

Layer / File(s) Summary
QueryDataForFilters conditional type
packages/query-core/src/queryClient.ts
Internal conditional type that extracts the data type associated with a QueryFilters shape, falling back to unknown.
setQueriesData overload update
packages/query-core/src/queryClient.ts
setQueriesData method overloads are updated to derive updater and return tuple data types from QueryDataForFilters<TQueryFilters> instead of TQueryFnData, improving type inference based on filter shapes.
Type test assertions and cleanup
packages/query-core/src/__tests__/queryClient.test-d.tsx
Fully typed usage tests now assert queriesData2 carries [QueryKey, TData | undefined]; untyped arguments test TODO comment removed.

🎯 2 (Simple) | ⏱️ ~8 minutes

🐰 With filters refined and types reconfirmed,
Data shapes now inferred, no longer unlearned,
A hoppy refactor of generics so bright,
Makes queries precise and their types ever right!

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Title check ✅ Passed The title directly and concisely describes the main change: fixing type inference for setQueriesData to use query filters instead of generic data types.
Description check ✅ Passed The description covers all essential sections: it summarizes the fix, lists specific changes made, and documents validation steps performed.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ 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 and usage tips.

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.

1 participant