Skip to content

docs: document the select typing caveat for parallel-queries hooks#10984

Open
manudeli wants to merge 3 commits into
mainfrom
docs/queries-select-typing
Open

docs: document the select typing caveat for parallel-queries hooks#10984
manudeli wants to merge 3 commits into
mainfrom
docs/queries-select-typing

Conversation

@manudeli

@manudeli manudeli commented Jun 25, 2026

Copy link
Copy Markdown
Collaborator

Inlining a select on a query object passed to useQueries / useSuspenseQueries can't infer its data argument from the sibling queryFn and falls back to unknown — a known TypeScript limitation (#6556).

This PR documents the two workarounds (annotate the select parameter, or define the query with the queryOptions helper) and adds type tests guarding the behavior.

Scoped to React for an easier review. The other framework adapters (Preact, Solid, Vue, Svelte, Angular) share the same caveat and can follow this exact pattern in separate PRs.

🎯 Changes

  • Document the select typing caveat + workarounds in:
    • docs/framework/react/guides/parallel-queries.md
    • docs/framework/react/reference/useQueries.md
    • docs/framework/react/reference/useSuspenseQueries.md
  • Add type tests guarding the behavior:
    • packages/react-query/src/__tests__/useQueries.test-d.tsx
    • packages/react-query/src/__tests__/useSuspenseQueries.test-d.tsx

Verified locally: vitest --typecheck on both test files passes (41 type tests, no errors).

✅ Checklist

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

🚀 Release Impact

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

Summary by CodeRabbit

  • Documentation

    • Added guidance for TypeScript users on select typing with query lists, including common inference limits and recommended workarounds.
    • Clarified that using the helper for query definitions can preserve better type inference, even when overriding select.
    • Added a note that the same typing behavior applies to the suspense-based query API.
  • Tests

    • Expanded type-check coverage to verify the documented TypeScript behavior across several query configuration patterns.

@coderabbitai

coderabbitai Bot commented Jun 25, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

📝 Walkthrough

Walkthrough

Adds TypeScript guidance for select inference in useQueries and useSuspenseQueries, including inline query limitations, queryOptions usage, and matching declaration tests for the documented patterns.

Changes

TypeScript select typing

Layer / File(s) Summary
useQueries limitation and inline inference
docs/framework/react/guides/parallel-queries.md, docs/framework/react/reference/useQueries.md, packages/react-query/src/__tests__/useQueries.test-d.tsx
Adds select typing notes for useQueries and tests inline query objects with and without an annotated select parameter.
useQueries queryOptions overrides
packages/react-query/src/__tests__/useQueries.test-d.tsx
Adds tests for direct queryOptions usage, re-wrapped options, and spread overrides that change the inferred data type.
useSuspenseQueries limitation and inference
docs/framework/react/reference/useSuspenseQueries.md, packages/react-query/src/__tests__/useSuspenseQueries.test-d.tsx
Adds the select typing note for useSuspenseQueries and tests inline, direct queryOptions, and spread override cases.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~15 minutes

Suggested labels

package: react-query

Suggested reviewers

  • TkDodo

Poem

A bunny hopped by with a type-safe cheer,
select can be tricky, but now it’s clear!”
With queryOptions bright, through the code I run,
useQueries and friends now infer just fine. 🐇

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly summarizes the main change: documenting the select typing caveat for parallel-query hooks.
Description check ✅ Passed The description matches the template with changes, checklist, and release impact sections filled out.
Docstring Coverage ✅ Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%.
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 docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch docs/queries-select-typing

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

@nx-cloud

nx-cloud Bot commented Jun 25, 2026

Copy link
Copy Markdown

View your CI Pipeline Execution ↗ for commit f9b201e

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

☁️ Nx Cloud last updated this comment at 2026-06-25 17:09:18 UTC

@github-actions

Copy link
Copy Markdown
Contributor

🚀 Changeset Version Preview

No changeset entries found. Merging this PR will not cause a version bump for any packages.

@manudeli manudeli self-assigned this Jun 25, 2026
@manudeli manudeli force-pushed the docs/queries-select-typing branch from 8880f46 to bb8f37a Compare June 25, 2026 14:59
@manudeli manudeli requested a review from Copilot June 25, 2026 15:00
@pkg-pr-new

pkg-pr-new Bot commented Jun 25, 2026

Copy link
Copy Markdown
More templates

@tanstack/angular-query-experimental

npm i https://pkg.pr.new/@tanstack/angular-query-experimental@10984

@tanstack/eslint-plugin-query

npm i https://pkg.pr.new/@tanstack/eslint-plugin-query@10984

@tanstack/lit-query

npm i https://pkg.pr.new/@tanstack/lit-query@10984

@tanstack/preact-query

npm i https://pkg.pr.new/@tanstack/preact-query@10984

@tanstack/preact-query-devtools

npm i https://pkg.pr.new/@tanstack/preact-query-devtools@10984

@tanstack/preact-query-persist-client

npm i https://pkg.pr.new/@tanstack/preact-query-persist-client@10984

@tanstack/query-async-storage-persister

npm i https://pkg.pr.new/@tanstack/query-async-storage-persister@10984

@tanstack/query-broadcast-client-experimental

npm i https://pkg.pr.new/@tanstack/query-broadcast-client-experimental@10984

@tanstack/query-core

npm i https://pkg.pr.new/@tanstack/query-core@10984

@tanstack/query-devtools

npm i https://pkg.pr.new/@tanstack/query-devtools@10984

@tanstack/query-persist-client-core

npm i https://pkg.pr.new/@tanstack/query-persist-client-core@10984

@tanstack/query-sync-storage-persister

npm i https://pkg.pr.new/@tanstack/query-sync-storage-persister@10984

@tanstack/react-query

npm i https://pkg.pr.new/@tanstack/react-query@10984

@tanstack/react-query-devtools

npm i https://pkg.pr.new/@tanstack/react-query-devtools@10984

@tanstack/react-query-next-experimental

npm i https://pkg.pr.new/@tanstack/react-query-next-experimental@10984

@tanstack/react-query-persist-client

npm i https://pkg.pr.new/@tanstack/react-query-persist-client@10984

@tanstack/solid-query

npm i https://pkg.pr.new/@tanstack/solid-query@10984

@tanstack/solid-query-devtools

npm i https://pkg.pr.new/@tanstack/solid-query-devtools@10984

@tanstack/solid-query-persist-client

npm i https://pkg.pr.new/@tanstack/solid-query-persist-client@10984

@tanstack/svelte-query

npm i https://pkg.pr.new/@tanstack/svelte-query@10984

@tanstack/svelte-query-devtools

npm i https://pkg.pr.new/@tanstack/svelte-query-devtools@10984

@tanstack/svelte-query-persist-client

npm i https://pkg.pr.new/@tanstack/svelte-query-persist-client@10984

@tanstack/vue-query

npm i https://pkg.pr.new/@tanstack/vue-query@10984

@tanstack/vue-query-devtools

npm i https://pkg.pr.new/@tanstack/vue-query-devtools@10984

commit: f9b201e

@github-actions

Copy link
Copy Markdown
Contributor

size-limit report 📦

Path Size
react full 12.13 KB (0%)
react minimal 9.08 KB (0%)

@manudeli manudeli force-pushed the docs/queries-select-typing branch from bb8f37a to a573e02 Compare June 25, 2026 15:05

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Pull request overview

This PR documents a TypeScript inference limitation when using an inline select inside query objects passed to React’s useQueries / useSuspenseQueries, and adds type-level tests to lock in the observed behavior and recommended workarounds.

Changes:

  • Added React docs explaining why inline select parameters fall back to unknown and the two supported workarounds (annotate the parameter, or use queryOptions).
  • Added/expanded vitest --typecheck tests for useQueries and useSuspenseQueries to guard the inference behavior across inline queries and queryOptions usage.
  • Linked the useSuspenseQueries reference back to the new useQueries TypeScript caveat section for discoverability.

Reviewed changes

Copilot reviewed 5 out of 5 changed files in this pull request and generated 4 comments.

Show a summary per file
File Description
docs/framework/react/guides/parallel-queries.md Adds a guide callout warning about inline select inference and points to workarounds.
docs/framework/react/reference/useQueries.md Adds a dedicated “TypeScript: typing the select option” section with examples and workarounds.
docs/framework/react/reference/useSuspenseQueries.md Adds a short note linking to the useQueries caveat section and recommending the same workarounds.
packages/react-query/src/tests/useQueries.test-d.tsx Adds type tests covering select inference limitations and queryOptions workaround behavior.
packages/react-query/src/tests/useSuspenseQueries.test-d.tsx Adds analogous type tests for useSuspenseQueries, including spread + override scenarios.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

queries: [
{
...options,
// @ts-expect-error the spread select argument has no inferred type without an annotation
queries: [
{
...options,
// @ts-expect-error the spread select argument has no inferred type without an annotation
})
useQueries({
queries: [
// @ts-expect-error the spread select argument is `unknown` without an annotation
})
useQueries({
queries: [
// @ts-expect-error the spread select argument is `unknown` without an annotation
@manudeli manudeli force-pushed the docs/queries-select-typing branch from a573e02 to 51f4d08 Compare June 25, 2026 15:13
Inlining a `select` on a query object passed to `useQueries` /
`useSuspenseQueries` can't infer its `data` argument from the sibling
`queryFn` and falls back to `unknown` — a known TypeScript limitation
(#6556).

Document the two workarounds (annotate the `select` parameter, or define
the query with the `queryOptions` helper) in the React docs, and add type
tests guarding the behavior. Scoped to React for an easier review; the
other framework adapters can follow the same pattern in separate PRs.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
@manudeli manudeli force-pushed the docs/queries-select-typing branch from 4b71638 to 6d3de44 Compare June 25, 2026 16:14

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 5 out of 5 changed files in this pull request and generated 1 comment.

})
```

The same applies to [`useSuspenseQueries`](./useSuspenseQueries.md).
@manudeli manudeli marked this pull request as ready for review June 25, 2026 16:27
@manudeli manudeli requested a review from TkDodo June 25, 2026 16:27

@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)
docs/framework/react/reference/useSuspenseQueries.md (1)

19-20: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick win

Clarify that queryOptions must be used directly (or re-wrapped) for this inference benefit.

Current wording can be read as “using queryOptions always keeps select inference,” but the added tests show spread + inline overriding select still needs an explicit parameter annotation. Consider tightening the sentence to reflect that distinction.

🤖 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 `@docs/framework/react/reference/useSuspenseQueries.md` around lines 19 - 20,
The useSuspenseQueries docs wording is too broad about select inference with
queryOptions; clarify that the inference benefit only applies when queryOptions
is used directly or when it is re-wrapped, not when its result is spread and
select is overridden inline. Update the sentence in useSuspenseQueries.md to
mirror the select typing caveat from useQueries.md and mention that annotating
the select parameter is still needed in the spread/override case, using
queryOptions as the key reference.
🤖 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 `@docs/framework/react/reference/useSuspenseQueries.md`:
- Around line 19-20: The useSuspenseQueries docs wording is too broad about
select inference with queryOptions; clarify that the inference benefit only
applies when queryOptions is used directly or when it is re-wrapped, not when
its result is spread and select is overridden inline. Update the sentence in
useSuspenseQueries.md to mirror the select typing caveat from useQueries.md and
mention that annotating the select parameter is still needed in the
spread/override case, using queryOptions as the key reference.

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: a6a20047-4962-4c37-a636-ab8d7ff10e65

📥 Commits

Reviewing files that changed from the base of the PR and between 0298c90 and 7a78664.

📒 Files selected for processing (5)
  • docs/framework/react/guides/parallel-queries.md
  • docs/framework/react/reference/useQueries.md
  • docs/framework/react/reference/useSuspenseQueries.md
  • packages/react-query/src/__tests__/useQueries.test-d.tsx
  • packages/react-query/src/__tests__/useSuspenseQueries.test-d.tsx

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.

2 participants