docs: document the select typing caveat for parallel-queries hooks#10984
docs: document the select typing caveat for parallel-queries hooks#10984manudeli wants to merge 3 commits into
select typing caveat for parallel-queries hooks#10984Conversation
📝 WalkthroughWalkthroughAdds TypeScript guidance for ChangesTypeScript
Estimated code review effort🎯 2 (Simple) | ⏱️ ~15 minutes Suggested labels
Suggested reviewers
Poem
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
Comment |
|
View your CI Pipeline Execution ↗ for commit f9b201e
☁️ Nx Cloud last updated this comment at |
🚀 Changeset Version PreviewNo changeset entries found. Merging this PR will not cause a version bump for any packages. |
8880f46 to
bb8f37a
Compare
size-limit report 📦
|
bb8f37a to
a573e02
Compare
There was a problem hiding this comment.
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
selectparameters fall back tounknownand the two supported workarounds (annotate the parameter, or usequeryOptions). - Added/expanded
vitest --typechecktests foruseQueriesanduseSuspenseQueriesto guard the inference behavior across inline queries andqueryOptionsusage. - Linked the
useSuspenseQueriesreference back to the newuseQueriesTypeScript 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 |
a573e02 to
51f4d08
Compare
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>
4b71638 to
6d3de44
Compare
| }) | ||
| ``` | ||
|
|
||
| The same applies to [`useSuspenseQueries`](./useSuspenseQueries.md). |
There was a problem hiding this comment.
🧹 Nitpick comments (1)
docs/framework/react/reference/useSuspenseQueries.md (1)
19-20: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick winClarify that
queryOptionsmust be used directly (or re-wrapped) for this inference benefit.Current wording can be read as “using
queryOptionsalways keepsselectinference,” but the added tests show spread + inline overridingselectstill 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
📒 Files selected for processing (5)
docs/framework/react/guides/parallel-queries.mddocs/framework/react/reference/useQueries.mddocs/framework/react/reference/useSuspenseQueries.mdpackages/react-query/src/__tests__/useQueries.test-d.tsxpackages/react-query/src/__tests__/useSuspenseQueries.test-d.tsx
Inlining a
selecton a query object passed touseQueries/useSuspenseQueriescan't infer itsdataargument from the siblingqueryFnand falls back tounknown— a known TypeScript limitation (#6556).This PR documents the two workarounds (annotate the
selectparameter, or define the query with thequeryOptionshelper) and adds type tests guarding the behavior.🎯 Changes
selecttyping caveat + workarounds in:docs/framework/react/guides/parallel-queries.mddocs/framework/react/reference/useQueries.mddocs/framework/react/reference/useSuspenseQueries.mdpackages/react-query/src/__tests__/useQueries.test-d.tsxpackages/react-query/src/__tests__/useSuspenseQueries.test-d.tsxVerified locally:
vitest --typecheckon both test files passes (41 type tests, no errors).✅ Checklist
pnpm run test:pr.🚀 Release Impact
Summary by CodeRabbit
Documentation
selecttyping with query lists, including common inference limits and recommended workarounds.select.Tests