fix(vue-query): allow computed ref as queryKey property in queryOptions#10530
fix(vue-query): allow computed ref as queryKey property in queryOptions#10530KimHyeongRae0 wants to merge 1 commit intoTanStack:mainfrom
Conversation
📝 WalkthroughWalkthroughThis pull request fixes a regression in Changes
Estimated code review effort🎯 2 (Simple) | ⏱️ ~10 minutes Poem
🚥 Pre-merge checks | ✅ 3✅ Passed checks (3 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ 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.
🧹 Nitpick comments (1)
packages/vue-query/src/__tests__/queryOptions.test-d.ts (1)
302-323: Optional: strengthen the type assertions.
expectTypeOf(options.queryKey).not.toBeUndefined()only verifies the property isn'tundefined— it wouldn't have caught the original regression (a TS2769 on thequeryOptionscall, not on the resultingqueryKeytype). The real guarantee under test is that thequeryOptions({...})call compiles. Consider usingassertType(...)around the call (as the excess-property test at line 12 does) or asserting the concrete unwrapped key type, e.g.:♻️ Stronger assertion example
- expectTypeOf(options.queryKey).not.toBeUndefined() + expectTypeOf(options.queryKey).toEqualTypeOf<readonly ['foo', string | null]>()That said, this mirrors the style of the adjacent
enabledtests, so this is purely an optional nit.🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@packages/vue-query/src/__tests__/queryOptions.test-d.ts` around lines 302 - 323, The test currently only checks that options.queryKey is not undefined which wouldn't catch a compilation regression in the queryOptions(...) call; update the tests using the queryOptions symbol (the two blocks with id/ref) to assert compilation and concrete types instead—either wrap the queryOptions({...}) call with assertType(...) (like the excess-property test) or replace the expectTypeOf lines with a stronger assertion such as assertTypeOf(options.queryKey) or assertTypeOf(options).toMatchTypeOf<ExpectedKeyType>() so the test fails on a TS error at the call site rather than only checking for undefined.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Nitpick comments:
In `@packages/vue-query/src/__tests__/queryOptions.test-d.ts`:
- Around line 302-323: The test currently only checks that options.queryKey is
not undefined which wouldn't catch a compilation regression in the
queryOptions(...) call; update the tests using the queryOptions symbol (the two
blocks with id/ref) to assert compilation and concrete types instead—either wrap
the queryOptions({...}) call with assertType(...) (like the excess-property
test) or replace the expectTypeOf lines with a stronger assertion such as
assertTypeOf(options.queryKey) or
assertTypeOf(options).toMatchTypeOf<ExpectedKeyType>() so the test fails on a TS
error at the call site rather than only checking for undefined.
ℹ️ Review info
⚙️ Run configuration
Configuration used: defaults
Review profile: CHILL
Plan: Pro
Run ID: d18de6f6-67ef-4018-a24f-0bb7367f49b1
📒 Files selected for processing (3)
.changeset/fix-vue-query-options-query-key-reactive.mdpackages/vue-query/src/__tests__/queryOptions.test-d.tspackages/vue-query/src/queryOptions.ts
|
Thanks for the suggestion. I'm going to leave the assertion as |
🎯 Changes
Closes #10525.
Fixes a regression from #10452 where the
queryOptionshelper in@tanstack/vue-querystopped acceptingcomputedrefs,Refvalues, or other reactive values for thequeryKeyproperty. The earlier fix in #10465 only covered theenabledproperty, so user code likewas emitting
TS2769: No overload matches this callon every version since5.98.0.This PR narrows the fix to the
queryKeyproperty only (mirroring how #10465 special-casedenabled), so downstream usages likequeryClient.fetchQuery(options)— which depend on non-reactive core types for other properties — continue to work without regressions.Type tests added for both
computed(...)andref(...)asqueryKeyinpackages/vue-query/src/__tests__/queryOptions.test-d.ts.✅ Checklist
npx nx run @tanstack/vue-query:test:typesand the fullpnpm --filter @tanstack/vue-query testsuite (291 tests passed, no type errors).🚀 Release Impact
Summary by CodeRabbit
Release Notes
queryOptions.queryKeynow accepts reactive values (Ref, ComputedRef) in addition to plain arrays, restoring previously supported functionality.