fix(vue-query): align queryOptions with useQuery#11014
Conversation
📝 WalkthroughWalkthroughThis PR refactors Vue Query's type system by moving ChangesUseQueryOptions/UseInfiniteQueryOptions Type Relocation
Estimated code review effort: 3 (Moderate) | ~25 minutes Sequence Diagram(s)Not applicable — this PR is a type-only refactor without new control flow or multi-component runtime interactions. Suggested labels: Suggested reviewers: 🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✨ Finishing Touches🧪 Generate unit tests (beta)
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. Comment |
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 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.
Inline comments:
In `@packages/vue-query/src/queryOptions.ts`:
- Around line 105-109: Restore the missing getter overload in queryOptions so
`DefinedInitialQueryOptions` still supports `queryOptions(() => ({ initialData:
... }))` and preserves the defined-data inference used by `useQuery`; update the
`queryOptions` type signatures in `queryOptions.ts` to include the getter branch
alongside the existing `MaybeRefOrGetter` overload, and add a corresponding
getter-based type test to verify the “data is always defined” behavior.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: defaults
Review profile: CHILL
Plan: Pro
Run ID: 439a8355-5965-438b-90fc-f7e0042dc49d
📒 Files selected for processing (11)
packages/vue-query/src/__tests__/queryOptions.test-d.tspackages/vue-query/src/__tests__/queryOptions.test.tspackages/vue-query/src/__tests__/useQueries.test-d.tspackages/vue-query/src/index.tspackages/vue-query/src/infiniteQueryOptions.tspackages/vue-query/src/queryClient.tspackages/vue-query/src/queryOptions.tspackages/vue-query/src/useBaseQuery.tspackages/vue-query/src/useInfiniteQuery.tspackages/vue-query/src/useQueries.tspackages/vue-query/src/useQuery.ts
| options: MaybeRefOrGetter< | ||
| UseQueryOptions<TQueryFnData, TError, TData, TQueryFnData, TQueryKey> | ||
| >, | ||
| ): () => UndefinedInitialQueryOptions< | ||
| TQueryFnData, | ||
| TError, | ||
| TData, | ||
| TQueryKey | ||
| ): MaybeRefOrGetter< | ||
| UseQueryOptions<TQueryFnData, TError, TData, TQueryFnData, TQueryKey> |
There was a problem hiding this comment.
🎯 Functional Correctness | 🟠 Major | ⚡ Quick win
🧩 Analysis chain
🏁 Script executed:
#!/bin/bash
set -euo pipefail
echo "=== queryOptions overloads ==="
sed -n '76,115p' packages/vue-query/src/queryOptions.ts
echo
echo "=== useQuery type entry points ==="
sed -n '1,90p' packages/vue-query/src/useQuery.ts
echo
echo "=== existing type-test coverage for initialData ==="
rg -n "initialData" packages/vue-query/src/__tests__/queryOptions.test-d.ts packages/vue-query/src/__tests__/useQuery.test-d.tsRepository: TanStack/query
Length of output: 6378
Restore the getter overload for DefinedInitialQueryOptions. queryOptions(() => ({ initialData: ... })) still needs a defined-initial-data overload; otherwise it falls back to the generic MaybeRefOrGetter<UseQueryOptions<...>> branch and loses the “data is always defined” inference that useQuery relies on. Add the getter case to the type tests too.
🤖 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/vue-query/src/queryOptions.ts` around lines 105 - 109, Restore the
missing getter overload in queryOptions so `DefinedInitialQueryOptions` still
supports `queryOptions(() => ({ initialData: ... }))` and preserves the
defined-data inference used by `useQuery`; update the `queryOptions` type
signatures in `queryOptions.ts` to include the getter branch alongside the
existing `MaybeRefOrGetter` overload, and add a corresponding getter-based type
test to verify the “data is always defined” behavior.
🎯 Changes
queryOptions rejects some reactive options that useQuery accepts
I ran into this while using
queryOptionsin a Vue app. It rejects options thatuseQueryaccepts without any problem. The case that actually blocked me was a reactivequeryFnthat returnsskipToken, so the query stays idle until there's an input:If I pass that same object straight to
useQueryit type-checks. ThroughqueryOptionsit errors. So I can't move the options into a shared helper without the types getting in the way.Reproduction: https://codesandbox.io/p/devbox/2yzjz5
The reason is that
queryOptionsanduseQuerywere built on two different option types.queryOptionsonly treatedqueryKeyandenabledas reactive and required every other field (includingqueryFn) to be a plain non-reactive value, whileuseQuerytreats every field as reactive, which is what makes acomputedqueryFnwork.This aligns
queryOptionsandinfiniteQueryOptionswith the option typesuseQueryanduseInfiniteQueryalready use, so ifuseQueryaccepts it,queryOptionsaccepts it too.Breaking change
The
QueryOptionstype is no longer exported, since it no longer exists. UseUseQueryOptionsinstead.✅ Checklist
pnpm run test:pr.🚀 Release Impact
Summary by CodeRabbit
New Features
skipToken.Bug Fixes
queryKeyvalidation so invalid getter-based key shapes are now rejected consistently.Refactor