query icon indicating copy to clipboard operation
query copied to clipboard

upd(vue-query): Improve queryOptions() type

Open Serpentarius13 opened this issue 2 months ago โ€ข 3 comments

๐ŸŽฏ Changes

I changed UseQueryOptions and its derivatives UndefinedInitialQueryOptions / DefinedInitialQueryOptions to have base non-ref cases to later differentiate them in queryOptions function. I don't think I can foresee possible implications of this as I am a novice, but I'm thinking nothing bad will happen from splitting the types like that

โœ… Checklist

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

๐Ÿš€ Release Impact

  • [X] This change affects published code, and I have generated a changeset. I dont really know how this works, but I've done it I guess

Summary by CodeRabbit

  • Refactor
    • Improved TypeScript type definitions for query options and initial data to better support both plain and Vue-reactive configurations.
  • Chores
    • Added a patch-level changeset entry updating the package version.

Serpentarius13 avatar Oct 16 '25 19:10 Serpentarius13

๐Ÿฆ‹ Changeset detected

Latest commit: 8d3f77a4742dbfcf412383a631e55fdf4d701ce6

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 2 packages
Name Type
@tanstack/vue-query Patch
@tanstack/vue-query-devtools Patch

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

changeset-bot[bot] avatar Oct 16 '25 19:10 changeset-bot[bot]

Walkthrough

Refactors vue-query TypeScript types to support Vue reactive wrappers (Ref/ComputedRef) for query options, splitting UseQueryOptions into base/ref variants and updating queryOptions overloads to use generic conditional return types. Also adds a changeset marking a patch release.

Changes

Cohort / File(s) Summary
Changeset entry
\.changeset/seven-apes-boil.md
Adds a changeset noting a patch release that signals changes to the public UseQueryOptions types.
Query options overloads
packages/vue-query/src/queryOptions.ts
Rewrites queryOptions overloads to accept generic TOptions/TReturnQueryKey and return conditional intersections: Ref-aware or base-defined option variants depending on presence of a value property. Keeps passthrough overload.
useQuery type hierarchy
packages/vue-query/src/useQuery.ts
Replaces the monolithic UseQueryOptions with UseQueryOptionsBase, UseQueryOptionsRef, and combinable variants; splits initialData variants into Defined/Undefined + Base/Ref forms and updates useQuery overloads to use the new public option types.

Estimated code review effort

๐ŸŽฏ 4 (Complex) | โฑ๏ธ ~45 minutes

Possibly related PRs

  • TanStack/query#9668 โ€” Related changes to queryOptions TypeScript signatures in the core query package.
  • TanStack/query#9634 โ€” Related refactor introducing MaybeRef/reactive-wrapper typing patterns for infinite-query option overloads.

Suggested reviewers

  • manudeli
  • DamianOsipiuk

Poem

๐Ÿฐ Hop, hop, the types rearrange,

Ref and Base across the range,
Options snug in Vue's embrace,
Patch released โ€” a tidy trace,
I nibble bugs and leave a trace ๐Ÿฅ•

Pre-merge checks and finishing touches

โŒ Failed checks (1 warning)
Check name Status Explanation Resolution
Docstring Coverage โš ๏ธ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. You can run @coderabbitai generate docstrings to improve docstring coverage.
โœ… Passed checks (2 passed)
Check name Status Explanation
Title Check โœ… Passed The title "upd(vue-query): Improve queryOptions() type" is clearly and specifically related to the core change in the pull request. The changes focus on improving the type system for the queryOptions() function by introducing generic type parameters, conditional return types, and refactoring UseQueryOptions to support both base and reactive ref variants. The title is concise, avoids vague language, and accurately summarizes the primary modification that a teammate would understand when scanning commit history.
Description Check โœ… Passed The pull request description includes all three required sections from the template: the Changes section explains that UseQueryOptions and its derivatives were modified to include base non-ref cases for differentiation in the queryOptions function, the Checklist section has both items marked as completed, and the Release Impact section is checked with a note indicating a changeset was generated. While the Changes section could provide more technical depth about the conditional type system and the specific motivations for splitting the types, all required information is present and the description meets the threshold for completeness as most critical sections are filled out with meaningful content.
โœจ Finishing touches
  • [ ] ๐Ÿ“ Generate docstrings
๐Ÿงช Generate unit tests (beta)
  • [ ] Create PR with unit tests
  • [ ] Post copyable unit tests in a comment

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.

coderabbitai[bot] avatar Oct 16 '25 19:10 coderabbitai[bot]

๐Ÿค– Nx Cloud AI Fix Eligible

An automatically generated fix could have helped fix failing tasks for this run, but Self-healing CI is disabled for this workspace. Visit workspace settings to enable it and get automatic fixes in future runs.

To disable these notifications, a workspace admin can disable them in workspace settings.


View your CI Pipeline Execution โ†— for commit 8d3f77a4742dbfcf412383a631e55fdf4d701ce6

Command Status Duration Result
nx affected --targets=test:sherif,test:knip,tes... โŒ Failed 1m 5s View โ†—
nx run-many --target=build --exclude=examples/*... โŒ Failed 6s View โ†—

โ˜๏ธ Nx Cloud last updated this comment at 2025-10-17 09:53:13 UTC

nx-cloud[bot] avatar Oct 17 '25 03:10 nx-cloud[bot]