How to add types to default options so that they are displayed correctly?
import type { FetchOptions } from 'ofetch'
type ApiFetchOptionsExtra = {
skipAuthTokenProcessing?: boolean
preventLogout?: boolean
}
type ApiFetchOptions = FetchOptions & ApiFetchOptionsExtra // this
const api = $fetch.create({
baseURL: apiUrl,
async onRequest({ options }) {
options.preventLogout = true // here 1
// ...
},
// ...
})
api('asd', {
body: ...,
preventLogout: true, // here 2
})
Found such a solution:
declare module 'ofetch' {
interface ResolvedFetchOptions extends ApiFetchOptionsExtra {
}
interface FetchOptions extends ApiFetchOptionsExtra {
}
}