You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
When a ref is passed as a query key in combination with this package it throws a typescript error on useQuery:
Vue: No overload matches this call.
Overload 1 of 3,
(options: UndefinedInitialQueryOptions<string, Error, string, readonly ["value", "someQuery", string, Ref<string, string>]>, queryClient?: QueryClient | undefined): UseQueryReturnType<...>
, gave the following error.
Overload 2 of 3,
(options: DefinedInitialQueryOptions<string, Error, string, readonly ["value", "someQuery", string, Ref<string, string>]>, queryClient?: QueryClient | undefined): UseQueryDefinedReturnType<...>
, gave the following error.
Overload 3 of 3, '(options: UseQueryOptions<string, Error, string, string, readonly ["value", "someQuery", string, Ref<string, string>]>, queryClient?: QueryClient | undefined): UseQueryReturnType<...>', gave the following error.
This happens because the type of Ref is Ref<string> but it gets transformed to string under the hood causing the type mismatch. When I directly pass the args to useQuery it doesn't cause any problems. Same for when the ref is passed to queryKeys as ref.value it works fine.
import{createQueryKeys,mergeQueryKeys,}from"@lukemorales/query-key-factory";import{unref,typeRef,toValue,}from"vue";exportconstvalueQueries=createQueryKeys("value",{someQuery: (val: Ref<string>)=>{return{queryKey: ["byTool",val],queryFn: async()=>`My value is ${unref(val)}`,};},someOtherQuery: (val: Ref<string>)=>{return{queryKey: ["byTool",toValue(val)]asconst,queryFn: async()=>`My value is ${unref(val)}`,};},});exportconstqueries=mergeQueryKeys(valueQueries);
<script setup lang="ts">
importHelloWorldfrom'./components/HelloWorld.vue'importTheWelcomefrom'./components/TheWelcome.vue'import {useQuery} from"@tanstack/vue-query";import {queries} from"@/queries";import {ref, unref} from"vue";const val =ref('')// works fineconst appQuery =useQuery({ queryKey: ["byTool", val],queryFn: async () =>`My value is ${unref(val)}`,});// error!const someQuery =useQuery(queries.value.someQuery(val))// works fineconst someOtherQuery =useQuery(queries.value.someOtherQuery(val))
</script>
When a ref is passed as a query key in combination with this package it throws a typescript error on
useQuery
:This happens because the type of
Ref
isRef<string>
but it gets transformed tostring
under the hood causing the type mismatch. When I directly pass the args touseQuery
it doesn't cause any problems. Same for when the ref is passed to queryKeys asref.value
it works fine.Example repository: https://github.com/egonm12/vue-query-key-factory
The text was updated successfully, but these errors were encountered: