mattiagpg
mattiagpg
NNuxt
Created by mattiagpg on 3/5/2025 in #❓・help
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)
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!
5 replies