Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

4 beta, useQuery No overload matches this call. #3502

Closed
mozeryansky opened this issue Apr 13, 2022 · 1 comment
Closed

4 beta, useQuery No overload matches this call. #3502

mozeryansky opened this issue Apr 13, 2022 · 1 comment

Comments

@mozeryansky
Copy link

Describe the bug

Type error: No overload matches this call.
  Overload 1 of 3, '(queryKey: QueryKey, options?: Omit<UseQueryOptions<[Trade], unknown, [Trade], QueryKey>, "queryKey"> | undefined): UseQueryResult<...>', gave the following error.
    Argument of type 'string' is not assignable to parameter of type 'QueryKey'.
  Overload 2 of 3, '(queryKey: QueryKey, queryFn: QueryFunction<[Trade], QueryKey>, options?: Omit<UseQueryOptions<[Trade], unknown, [Trade], QueryKey>, "queryKey" | "queryFn"> | undefined): UseQueryResult<...>', gave the following error.
    Argument of type 'string' is not assignable to parameter of type 'QueryKey'.

  11 |   const queryClient = useQueryClient()
  12 | 
> 13 |   const { data } = useQuery(myQueryKey, async () => {

where

export default function useMyHook() {
  const myQueryKey = 'myQueryKey'

  const queryClient = useQueryClient()

  const { data } = useQuery(myQueryKey, async () => {
     ...
  })
...

If I change it to const { data } = useQuery([myQueryKey], async () => { then it's fine, but this used to work in non-beta.

Your minimal, reproducible example

^

Steps to reproduce

useQuery with variable as key

Expected behavior

no compiler error

How often does this bug happen?

No response

Screenshots or Videos

No response

Platform

macOS

react-query version

4.0.0-beta.3

TypeScript version

4.6.3

Additional context

No response

@TkDodo
Copy link
Collaborator

TkDodo commented Apr 13, 2022

Have you read the migration guide? Because the fact that keys need to be an array is one of the breaking changes in v4: https://react-query-beta.tanstack.com/guides/migrating-to-react-query-4

@TkDodo TkDodo closed this as completed Apr 13, 2022
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

No branches or pull requests

2 participants