Skip to content

fix(vue-query): preserve useQuery inference for spread queryOptions o…#10975

Open
nijuse wants to merge 1 commit into
TanStack:mainfrom
nijuse:main
Open

fix(vue-query): preserve useQuery inference for spread queryOptions o…#10975
nijuse wants to merge 1 commit into
TanStack:mainfrom
nijuse:main

Conversation

@nijuse

@nijuse nijuse commented Jun 22, 2026

Copy link
Copy Markdown

🎯 Changes

Fixes a type inference bug in useQuery when spreading queryOptions() and overriding non-data-shaping options like enabled.

Root cause: In UseQueryOptions, queryKey was typed through the generic MaybeRefDeep<...> path (same as other options). When using the spread + override pattern, TQueryKey was not preserved correctly and generics widened to unknown.

Fix: Add a dedicated branch for queryKey, typing it as MaybeRefOrGetter<TQueryKey> (similar to the existing enabled branch). Both patterns now infer the same data type:

// direct
useQuery(fooQueryOptions('1'))

// spread + enabled override
useQuery({ ...fooQueryOptions('1'), enabled: () => true })

βœ… 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

  • Tests

    • Enhanced type-checking for query options spreading behavior.
  • Refactor

    • Improved type definition formatting for better code readability.

@coderabbitai

coderabbitai Bot commented Jun 22, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

No actionable comments were generated in the recent review. πŸŽ‰

ℹ️ Recent review info
βš™οΈ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 4171dba9-3487-4b0e-bc54-363d8b969022

πŸ“₯ Commits

Reviewing files that changed from the base of the PR and between 4f11927 and fc123de.

πŸ“’ Files selected for processing (2)
  • packages/vue-query/src/__tests__/useQuery.test-d.ts
  • packages/vue-query/src/useQuery.ts

πŸ“ Walkthrough

Walkthrough

Reformats the UseQueryOptions mapped-type fallback branch in useQuery.ts across additional lines without changing logic. Adds a new type-definition test in useQuery.test-d.ts that imports MaybeRefOrGetter and toValue from vue-demi and asserts that spreading queryOptions with an enabled override preserves the inferred data type.

Changes

UseQueryOptions spread type inference fix

Layer / File(s) Summary
UseQueryOptions mapped-type reformatting and type test
packages/vue-query/src/useQuery.ts, packages/vue-query/src/__tests__/useQuery.test-d.ts
Reformats the MaybeRefDeep<QueryObserverOptions<...>[Property]> fallback branch across multiple lines. Adds MaybeRefOrGetter and toValue imports and a new expectTypeOf test verifying that { id: string } | null | undefined is preserved as data when queryOptions is spread with an enabled: () => true override.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~5 minutes

Possibly related issues

Poem

πŸ‡ A spread with enabled once broke the type,
The rabbit reformatted, set things aright.
MaybeRefOrGetter joined the test file too,
expectTypeOf checked the shape rang true.
No more lost unions β€” null | undefined stays!
Hops of joy for well-typed query days. πŸŽ‰

πŸš₯ Pre-merge checks | βœ… 5
βœ… Passed checks (5 passed)
Check name Status Explanation
Title check βœ… Passed The title accurately summarizes the main change: fixing type inference for spread queryOptions in useQuery.
Description check βœ… Passed The description follows the template with clear 'Changes' section explaining the bug and fix, completed checklist items, and addressed release impact.
Docstring Coverage βœ… Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
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 unit tests (beta)
  • Create PR with unit tests

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.

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.

1 participant