NuxtN
Nuxt6mo ago
8 replies
LordGhandi

Custom use fetch type error

I'm trying to build a custom use fetch composable and I have followed the nuxt documentation.
The custom composable is always screaming a typescript error to me that there is no overload for this useFetchCall with these types.
Vue: No overload matches this call.
Overload 1 of 2,
(request: NitroFetchRequest | Ref<NitroFetchRequest, NitroFetchRequest> | (() => NitroFetchRequest), opts?: UseFetchOptions<...> | undefined): AsyncData<...>
, gave the following error.
Overload 2 of 2,
(request: NitroFetchRequest | Ref<NitroFetchRequest, NitroFetchRequest> | (() => NitroFetchRequest), opts?: UseFetchOptions<...> | undefined): AsyncData<...>
, gave the following error.


This is the code snippet:
import type { UseFetchOptions } from 'nuxt/app'
import type {ProblemDetails} from "~/types";
import {FetchError} from "ofetch";

export function useAPI<T>(
    url: string | (() => string),
    options?: UseFetchOptions<T>,
) {
  return useFetch<T, FetchError<ProblemDetails>>(url, {
    ...options,
    $fetch: useNuxtApp().$api 
  })
}
Was this page helpful?