This commit is contained in:
2026-08-25 11:38:20 +08:00
parent 351fb15d69
commit d8cc3ec655
5 changed files with 65 additions and 46 deletions
+9 -8
View File
@@ -1,4 +1,5 @@
import { RequestFn, RequestOptions, Base62Param } from './types/httpRequest';
import { HttpResponseChainable } from './types/httpResponse';
export default HttpRequest;
declare class HttpRequest {
/**
@@ -18,36 +19,36 @@ declare class HttpRequest {
* 发起请求,支持缓存与并发合并
* @param {RequestOptions} options
* @param {boolean} [isCacheRequest]
* @returns {any} 返回 Proxy 包裹的 Promise,支持链式调用 .then / .catch / .msg / .resp
* @returns {HttpResponseChainable} 返回 Proxy 包裹的 Promise,支持链式调用 .then / .catch / .msg / .resp
*/
request: ({ url, method, ...params }: RequestOptions, isCacheRequest?: boolean) => any;
request: ({ url, method, ...params }: RequestOptions, isCacheRequest?: boolean) => HttpResponseChainable;
/**
* GET 请求
* @param {string} url
* @param {Record<string, unknown>} [params]
*/
get: (url: string, params?: Record<string, unknown>) => any;
get: (url: string, params?: Record<string, unknown>) => HttpResponseChainable;
/**
* POST 请求
* @param {string} url
* @param {unknown} [data]
* @param {Record<string, unknown>} [params]
*/
post: (url: string, data?: unknown, params?: Record<string, unknown>) => any;
post: (url: string, data?: unknown, params?: Record<string, unknown>) => HttpResponseChainable;
/**
* PUT 请求
* @param {string} url
* @param {unknown} [data]
* @param {Record<string, unknown>} [params]
*/
put: (url: string, data?: unknown, params?: Record<string, unknown>) => any;
put: (url: string, data?: unknown, params?: Record<string, unknown>) => HttpResponseChainable;
/**
* DELETE 请求
* @param {string} url
* @param {unknown} [data]
* @param {Record<string, unknown>} [params]
*/
del: (url: string, data?: unknown, params?: Record<string, unknown>) => any;
del: (url: string, data?: unknown, params?: Record<string, unknown>) => HttpResponseChainable;
/**
* 下载(待实现)
* @param {string} url
@@ -59,13 +60,13 @@ declare class HttpRequest {
* @param {string} url
* @param {Record<string, unknown>} [params]
*/
cache: (url: string, params?: Record<string, unknown>) => any;
cache: (url: string, params?: Record<string, unknown>) => HttpResponseChainable;
/**
* 通过 Base62 编码参数请求列表接口
* @param {string} code
* @param {Base62Param} [base62param]
*/
list: (code: string, base62param?: Base62Param) => any;
list: (code: string, base62param?: Base62Param) => HttpResponseChainable;
getAppInfo: () => void;
/**
* 清除缓存
+10
View File
@@ -25,6 +25,16 @@ export type HttpResponseProxyAPI = {
finally: (fn?: () => void) => Promise<unknown>
}
/**
* HttpResponse 上所有"可链式调用"的方法(then/catch/finally 来自 Proxymsg/resp 来自
* HttpResponse 本身——用 Pick 直接引用类上的定义,避免和 @overload 的类型重复维护)。
*
* request() 返回的是一个包裹着 pending Promise 的 Proxy:对任意 key 的访问都会返回一个
* "等 Promise resolve 后再转发调用"的函数,并不提供 code/data 这类同步属性,
* 所以它的类型应该是这个(不能直接用 HttpResponseProxy,那个类型意味着同步属性也存在)。
*/
export type HttpResponseChainable = HttpResponseProxyAPI & Pick<HttpResponse, 'msg' | 'resp'>
/**
* HttpResponse 最终对外类型
*