export type RequestMethod = 'get' | 'delete' | 'head' | 'options' | 'post' | 'put' | 'patch' | 'purge' | 'link' | 'unlink'; export interface FetchOptions extends RequestInit { /** * The request url. */ url?: string; /** * The request method. You can override the default request method type by * specifying your request method type. * For example `FetchOptions`. */ method?: M; /** * The data to send to the server. The data will be stringified using * `JSON.stringify` before being sent to the server and the `Content-Type` * request header will be set to `application/json` if not set. * * If the `body` field is set (not `null` or `undefined`), the `json` * field will be ignored and we will not set the `Content-Type` header. */ json?: any; /** * The base URL to prepend to `url` if `url` is a relative url. */ baseURL?: string; /** * The value to be encoded to query string to append to the url. */ query?: Record; /** * A function to encode the `query` value. * A query string must be returned without a leading question mark. * If this function is not set, the default one will be used. */ encodeQuery?: (query: Record) => string; } export interface FetchResponse { /** * The `Headers` object associated with the response. */ headers: Headers; /** * The response data. Parsed from the response body text with `JSON.parse`. * If parsing fails, this field will be set to the response body text and * the `error` field of the response will be set to the error thrown * during the parsing. */ json: T; /** * The error thrown while parsing the response body text with `JSON.parse`. * If no error has been thrown, the value of this field is `undefined`. */ error?: Error; /** * A boolean indicating whether the response was successful (status in the * range 200 – 299) or not. */ ok: boolean; /** * Indicates whether or not the response is the result of a redirect * (that is, its URL list has more than one entry). */ redirected: boolean; /** * The status code of the response. */ status: number; /** * The status message corresponding to the status code. (e.g., OK for 200). */ statusText: string; /** * The original response body text. */ text: string; /** * The type of the response (e.g., basic, cors). */ type: ResponseType; /** * The URL of the response. */ url: string; } export interface FetchMethod { (options: FetchOptions): Promise>; (options: FetchOptions, rawResponse: true): Promise; } declare const fetchWithJSON: FetchMethod; export default fetchWithJSON;