@msom/common
Version:
@msom/common
36 lines • 1.44 kB
TypeScript
import { OcPromise } from "../OcPromise";
type FetchUrl = Parameters<typeof fetch>[0];
type FetchOption = Exclude<Parameters<typeof fetch>[1], undefined> & {
params?: Record<string, any>;
};
export declare function createCancelRequest(url: FetchUrl, fetchInit?: FetchOption): OcPromise<Response, import("../OcPromise").OcPromiseRejectError, unknown>;
type OmitContentType = Exclude<string, "content-type" | "contentType">;
type JsonRequestHeaders = Headers | [OmitContentType, string][] | Record<OmitContentType, string>;
type JsonRequestOptions = Omit<FetchOption, "headers"> & {
headers?: JsonRequestHeaders;
};
/**
* 创建请求体是application/json的请求
* @param {FetchUrl} url
* @param {JsonRequestOptions} init
* @returns
*/
export declare function createJsonRequest(url: FetchUrl, init?: JsonRequestOptions): OcPromise<Response>;
/**
* 创建响应体是json格式的请求
* @template T
* @param {FetchUrl} url
* @param {FetchOption} init
* @returns {OcPromise<T>}
*/
export declare function createRequestJson<T>(url: FetchUrl, init?: FetchOption): OcPromise<T>;
/**
* 创建请求体是application/json、响应体是json格式的请求
* @template T
* @param {FetchUrl} url
* @param {JsonRequestOptions} init
* @returns {OcPromise<T>}
*/
export declare function createJsonRequestJson<T>(url: FetchUrl, init?: JsonRequestOptions): OcPromise<T>;
export {};
//# sourceMappingURL=createRequest.d.ts.map