In the standard fetch()
function, the BodyInit_
type restricts the assignment of objects to the body
property.
I am looking to create a custom wrapper for fetch that maintains the same signature as fetch
, but allows the second argument (options) to include a body value that can be an object.
How can I override this type restriction?
I have attempted the following:
type BodyInitType = RequestInit['body']
type WrappedRequestInit = Exclude<RequestInit, 'body'> & {
body: object
}
type WrappedFetch = (url: string, options: WrappedRequestInit) => Promise<Response>