@dazhicheng/utils 1.3.25 → 1.3.26
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/axios/type.d.ts +4 -25
- package/dist/index.esm.js.map +1 -1
- package/package.json +1 -1
package/dist/axios/type.d.ts
CHANGED
|
@@ -9,20 +9,17 @@ export interface BaseResponse<T = unknown> {
|
|
|
9
9
|
data: T;
|
|
10
10
|
}
|
|
11
11
|
export interface ExtendedAxiosRequestConfig extends AxiosRequestConfig {
|
|
12
|
+
/** 是否显示错误消息 */
|
|
12
13
|
showErrorMessage?: boolean;
|
|
14
|
+
/** 是否显示成功消息 */
|
|
13
15
|
showSuccessMessage?: boolean;
|
|
16
|
+
/** 是否隐藏 loading */
|
|
14
17
|
hideLoading?: boolean;
|
|
18
|
+
/** 是否返回所有数据 */
|
|
15
19
|
responseAllData?: boolean;
|
|
16
20
|
}
|
|
17
21
|
/**
|
|
18
22
|
* 将 OpenAPI 常见的「整包响应」类型解成运行时实际返回的 `data` 载荷类型。
|
|
19
|
-
* TtHttp 成功时返回 `res.data.data`(axios 的 body 里的 `data` 字段),因此泛型传 `ResponseResultX` 时应得到 `X` 里的 `data`。
|
|
20
|
-
* 若 T 本身没有 `data` 字段(例如直接传业务 DTO),则 T 原样返回。
|
|
21
|
-
*
|
|
22
|
-
* 注意:
|
|
23
|
-
* - 不能用 `T extends { data?: infer D }` 单独判断:会对任意对象成立并把 D 推断成 unknown。
|
|
24
|
-
* - `{ [key: string]: any }` 这类索引签名对象的 `keyof` 含 `string`,用 `string extends keyof T` 识别:此类按「不解包」处理(与 `request.post<Api.Common.Data>` 等用法兼容)。
|
|
25
|
-
* - 显式字段的 `ResponseResult*`(keyof 为若干字面量联合)则解包出 `data`。
|
|
26
23
|
*/
|
|
27
24
|
export type UnwrapApiResponse<T> = string extends keyof T ? T : T extends {
|
|
28
25
|
data?: infer D;
|
|
@@ -41,29 +38,11 @@ export type TtHttpFullResponse<T> = AxiosResponse<BaseResponse<UnwrapApiResponse
|
|
|
41
38
|
* @description TtHttp 实例方法类型:按 `responseAllData` 重载返回值,默认仅返回业务载荷 `UnwrapApiResponse<T>`。
|
|
42
39
|
*/
|
|
43
40
|
export interface TtHttpReturnType {
|
|
44
|
-
get<T>(config: OmitMethod & {
|
|
45
|
-
responseAllData: true;
|
|
46
|
-
}): Promise<TtHttpFullResponse<T>>;
|
|
47
41
|
get<T>(config?: OmitMethod): Promise<UnwrapApiResponse<T>>;
|
|
48
|
-
post<T>(config: OmitMethod & {
|
|
49
|
-
responseAllData: true;
|
|
50
|
-
}): Promise<TtHttpFullResponse<T>>;
|
|
51
42
|
post<T>(config?: OmitMethod): Promise<UnwrapApiResponse<T>>;
|
|
52
|
-
put<T>(config: OmitMethod & {
|
|
53
|
-
responseAllData: true;
|
|
54
|
-
}): Promise<TtHttpFullResponse<T>>;
|
|
55
43
|
put<T>(config?: OmitMethod): Promise<UnwrapApiResponse<T>>;
|
|
56
|
-
del<T>(config: OmitMethod & {
|
|
57
|
-
responseAllData: true;
|
|
58
|
-
}): Promise<TtHttpFullResponse<T>>;
|
|
59
44
|
del<T>(config?: OmitMethod): Promise<UnwrapApiResponse<T>>;
|
|
60
|
-
patch<T>(config: OmitMethod & {
|
|
61
|
-
responseAllData: true;
|
|
62
|
-
}): Promise<TtHttpFullResponse<T>>;
|
|
63
45
|
patch<T>(config?: OmitMethod): Promise<UnwrapApiResponse<T>>;
|
|
64
|
-
request<T>(config: ExtendedAxiosRequestConfig & {
|
|
65
|
-
responseAllData: true;
|
|
66
|
-
}): Promise<TtHttpFullResponse<T>>;
|
|
67
46
|
request<T>(config: ExtendedAxiosRequestConfig): Promise<UnwrapApiResponse<T>>;
|
|
68
47
|
logOut: () => void;
|
|
69
48
|
setBaseUrl: (url: string) => void;
|