/** * 支持的 HTTP 请求方法 */ export type HttpMethod = 'GET' | 'POST'; /** * 请求配置项 */ export interface XhrOptions { /** 请求方法,默认 'GET' */ method?: HttpMethod; /** 请求头 (Key-Value) */ headers?: Record; /** 请求体 (普通对象会被自动序列化为 JSON) */ body?: any; /** * 查询参数 (普通对象会被自动序列化为 URLSearchParams) * */ params?: Record; /** 是否携带 cookies 和跨域认证信息 */ withCredentials?: boolean; /** 超时时间(毫秒),默认 20000 */ timeout?: number; /** 响应类型,决定返回值的解析方式 */ responseType?: XMLHttpRequestResponseType; /** 上传/下载进度回调 */ onProgress?: (event: ProgressEvent) => void; } /** * 请求的响应内容 */ export interface XhrResponse { code: number; message: string; ttl: number; data: T; } /** * 主函数:发起 XMLHttpRequest 请求 */ export declare function xhrRequest(url: string, options?: XhrOptions): Promise>; export declare namespace xhrRequest { var get: RequestHelper; var getWithCredentials: RequestHelperWithAuth; var post: RequestHelper; var postWithCredentials: RequestHelperWithAuth; } type RequestHelper = (url: string, options?: Omit) => Promise>; type RequestHelperWithAuth = (url: string, options?: Omit) => Promise>; export {};