NuxtN
Nuxt2y ago
Flo

Preserve types in custom useFetch composable?

Probably just missing typescript knowledge... my custom fetch composable doesn't give me the type hints for the requested route while useFetch does that.

export async function useBetterFetch<T = any>(
  url: string,
  options: Parameters<typeof $fetch>[1] = {}
): Promise<T> {
  const requestHeaders = useRequestHeaders(["cookie"]);

  const headers = { ...options.headers, ...requestHeaders };

  return await $fetch<T>(url, { ...options, headers });
}
Was this page helpful?