@dazhicheng/utils 1.3.24 → 1.3.25

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.
@@ -30,18 +30,41 @@ export type UnwrapApiResponse<T> = string extends keyof T ? T : T extends {
30
30
  data: infer D;
31
31
  } ? D : T;
32
32
  /**
33
- * 请求成功时的返回类型:`responseAllData !== true` 时为业务 data;为 true 时为完整 Axios 响应。
34
- * 调用处若未传 `responseAllData: true`,可按 UnwrapApiResponse&lt;T&gt; 使用(或断言)。
33
+ * 请求成功时的运行时联合类型(实现层使用):`responseAllData !== true` 时为业务 data;为 true 时为完整 Axios 响应。
34
+ * 对外接口 {@link TtHttpReturnType} 使用重载区分,避免业务侧拿到 `| AxiosResponse` 联合导致与常用写法冲突。
35
35
  */
36
36
  export type TtHttpResult<T> = UnwrapApiResponse<T> | AxiosResponse<BaseResponse<UnwrapApiResponse<T>>>;
37
37
  type OmitMethod = Omit<ExtendedAxiosRequestConfig, "method">;
38
+ /** 完整 Axios 响应(与 `responseAllData: true` 时 request 泛型一致) */
39
+ export type TtHttpFullResponse<T> = AxiosResponse<BaseResponse<UnwrapApiResponse<T>>>;
40
+ /**
41
+ * @description TtHttp 实例方法类型:按 `responseAllData` 重载返回值,默认仅返回业务载荷 `UnwrapApiResponse&lt;T&gt;`。
42
+ */
38
43
  export interface TtHttpReturnType {
39
- get<T>(config: OmitMethod): Promise<TtHttpResult<T>>;
40
- post<T>(config: OmitMethod): Promise<TtHttpResult<T>>;
41
- put<T>(config: OmitMethod): Promise<TtHttpResult<T>>;
42
- del<T>(config: OmitMethod): Promise<TtHttpResult<T>>;
43
- patch<T>(config: OmitMethod): Promise<TtHttpResult<T>>;
44
- request<T>(config: ExtendedAxiosRequestConfig): Promise<TtHttpResult<T>>;
44
+ get<T>(config: OmitMethod & {
45
+ responseAllData: true;
46
+ }): Promise<TtHttpFullResponse<T>>;
47
+ get<T>(config?: OmitMethod): Promise<UnwrapApiResponse<T>>;
48
+ post<T>(config: OmitMethod & {
49
+ responseAllData: true;
50
+ }): Promise<TtHttpFullResponse<T>>;
51
+ post<T>(config?: OmitMethod): Promise<UnwrapApiResponse<T>>;
52
+ put<T>(config: OmitMethod & {
53
+ responseAllData: true;
54
+ }): Promise<TtHttpFullResponse<T>>;
55
+ put<T>(config?: OmitMethod): Promise<UnwrapApiResponse<T>>;
56
+ del<T>(config: OmitMethod & {
57
+ responseAllData: true;
58
+ }): Promise<TtHttpFullResponse<T>>;
59
+ del<T>(config?: OmitMethod): Promise<UnwrapApiResponse<T>>;
60
+ patch<T>(config: OmitMethod & {
61
+ responseAllData: true;
62
+ }): Promise<TtHttpFullResponse<T>>;
63
+ patch<T>(config?: OmitMethod): Promise<UnwrapApiResponse<T>>;
64
+ request<T>(config: ExtendedAxiosRequestConfig & {
65
+ responseAllData: true;
66
+ }): Promise<TtHttpFullResponse<T>>;
67
+ request<T>(config: ExtendedAxiosRequestConfig): Promise<UnwrapApiResponse<T>>;
45
68
  logOut: () => void;
46
69
  setBaseUrl: (url: string) => void;
47
70
  }