NuxtN
Nuxt11mo ago
4 replies
mattiagpg

Custom useAsyncData - $fetch TypeScript error🙏

Hello everybody,
I have followed the nuxt 3 guide to create a custom fetch client.
All seems to be right, but when I'm going to add TypeScript FetchError<CustomError> in useFetch, I receive this TypeScript error (I'm a TypeScript newbie):

No overload matches this call.
  Overload 1 of 2, '(request: NitroFetchRequest | Ref<NitroFetchRequest, NitroFetchRequest> | (() => NitroFetchRequest), opts?: UseFetchOptions<...> | undefined): AsyncData<...>', gave the following error.
    Type 'unknown' is not assignable to type '$Fetch<unknown, NitroFetchRequest> | undefined'.
  Overload 2 of 2, '(request: NitroFetchRequest | Ref<NitroFetchRequest, NitroFetchRequest> | (() => NitroFetchRequest), opts?: UseFetchOptions<...> | undefined): AsyncData<...>', gave the following error.
    Type 'unknown' is not assignable to type '$Fetch<unknown, NitroFetchRequest> | undefined'.(2769)


I have just upload in StackBlitz: https://stackblitz.com/edit/github-hxq8kzk2?file=composables%2FuseApi.ts

I hope that someone can help me 🙏

Thank you guy!
StackBlitzMattia
Create a new Nuxt project, module, layer or start from a theme with our collection of starters.
Nuxt - Starter - StackBlitz
Was this page helpful?