No overload matches this call #28 Creating a Reusable API Client

Hi, I’m stuck with this error message at lesson #28 of course #2:

No overload matches this call.
The last overload gave the following error.
Argument of type ‘{ queryKey: (string | GameQuery); queryFn: () => Promise<Game>; }’ is not assignable to parameter of type ‘QueryKey’.
Object literal may only specify known properties, and ‘queryKey’ does not exist in type ‘readonly unknown’.

The code however is still working. The squirly underline is under the queryKey but I only followed the changes made on queryFn.
Any suggestions on how to resolve this?

What’s the type of CACHE_KEY_GAMES in your constants.ts file?

Hi, I tried string and string array but also, as it is used by Mosh directly in the hook.

Mosh mentions in several lessons that when he forgets to use an arrow function for queryFn he gets the same kind of compilation error.

image

1 Like

The error is caused by initialData. Disabling this line removes the error at queryKey

My solution (to me initialData: initialGenres lookes cleaner
image

In lesson #32 Mosh addresses a similar issue. The type of the initialDate should just be of the same type ans the apiClient.getAll. Looking back at my code I added the next property without any thought - this broke my code in the first place.

image

make sure that next property isn’t required in the FetchRespone interface
export interface FetchResponse {
count: number;
next?: string | null;
results: T;
}