NuxtN
Nuxt3y ago
Markeem

Wrapping $fetch in composable with default options while retaining type safety

I managed to get autocomplete for the routes, but the return type is unknown. How can I get the return type working ? Example:

import type { NitroFetchRequest } from 'nitropack'

export function useFetchWithDefaultOptions(url: NitroFetchRequest) {
  return $fetch(url, {
    headers: {
      defaultHeader: 'value',
    },
  })
}
Was this page helpful?