TanStackT
TanStack3y ago
3 replies
slow-yellow

Getting type error when using string to invalidate queries

Hey,

I am following the invalidation query docs to invalidate all queries with the term rates as the first element in the query key array by using
  queryClient.invalidateQueries('rates');

I am using the useQueryClient hook to get the queryClient.

This clears the queries I want to clear, but I am getting a type error when I use the string:
No overload matches this call.
  Overload 1 of 2, '(filters?: InvalidateQueryFilters<unknown> | undefined, options?: InvalidateOptions | undefined): Promise<void>', gave the following error.
    Type '"rates"' has no properties in common with type 'InvalidateQueryFilters<unknown>'.
  Overload 2 of 2, '(queryKey?: QueryKey | undefined, filters?: InvalidateQueryFilters<unknown> | undefined, options?: InvalidateOptions | undefined): Promise<void>', gave the following error.
    Argument of type 'string' is not assignable to parameter of type 'readonly unknown[]'.ts(2769)

if I try putting it in an array:
  queryClient.invalidateQueries(['rates']);

the type error goes away but the query invalidation does not work. How can i fix this? Thanks
Was this page helpful?