NuxtN
Nuxt10mo ago
22 replies
Samuelreichoer

Custom Fetch Types not align

I have following custom composable function:

import type { UseFetchOptions } from '#app'

export function useCraftFetch<T>(
url: string | Request | Ref<string | Request> | (() => string | Request),
options: UseFetchOptions<T> = {}
) {
const { authToken } = useRuntimeConfig().public.craftcms
const headers = {
'Authorization': authToken,
}

const customOptions: UseFetchOptions<T> = {
...options,
headers: {
...headers,
...(options.headers || {})
}
}

return useFetch<T>(url, customOptions)
}

And I get a ts error in the useFetch part where customOptions is set. Why is that?
Was this page helpful?