fix(vue-query): fix queryOptions return type to expose all properties#10105
fix(vue-query): fix queryOptions return type to expose all properties#10105veeceey wants to merge 1 commit intoTanStack:mainfrom
Conversation
…nches
The queryOptions return type was a MaybeRef union type (T | Ref<T> | ComputedRef<T>)
intersected with { initialData?, queryKey }. TypeScript only shows properties common to
all union members, so only queryKey and initialData were accessible via dot notation.
Fix by using Exclude<T, Ref | ComputedRef> on the return type to remove the Ref and
ComputedRef branches, since queryOptions always returns a plain object. Also update
useQueries type inference to handle these plain types via DataTag-based matching.
Fixes TanStack#7892
🦋 Changeset detectedLatest commit: 551270e The changes in this PR will be included in the next version bump. This PR includes changesets to release 2 packages
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
📝 WalkthroughWalkthroughThis PR fixes a TypeScript type issue in Changes
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20 minutes Possibly related PRs
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 unit tests (beta)
No actionable comments were generated in the recent review. 🎉 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 |
Summary
queryOptionsreturn type in vue-query to expose all query option properties (queryFn,staleTime,select, etc.) for direct access, not justqueryKeyandinitialDataExclude<T, Ref | ComputedRef>to remove Ref/ComputedRef branches from theMaybeRefunion in the return type, sincequeryOptionsalways returns a plain objectuseQueriestype inference (GetUseQueryOptionsForUseQueriesandGetUseQueryResult) to handle the new plain return type via DataTag-based matchingqueryOptionsresultFixes #7892
Details
The root cause was that
UndefinedInitialQueryOptionsandDefinedInitialQueryOptionsare defined asMaybeRef<Inner> & { initialData }, whereMaybeRef<T> = T | Ref<T> | ComputedRef<T>. When TypeScript resolves property access on this union type, it only shows properties common to all union members. SinceRef<T>only has.valueandComputedRef<T>only has.value/.effect, the common properties were limited toqueryKey(from the& { queryKey }intersection) andinitialData.The fix uses
Exclude<T, Ref<any> | ComputedRef<any>>(aliased asPlainQueryOptions<T>) in thequeryOptionsreturn type to strip theRefandComputedRefbranches from the union. This is safe becausequeryOptionsalways accepts and returns plain objects, never Vue refs.Test plan
options.queryFnandoptions.queryKeyare accessibleSummary by CodeRabbit
queryOptions()to properly expose all query option properties (such asqueryFnandstaleTime) for direct access via dot notation, improving type inference and developer experience.