hook-fetch 2.0.7 → 2.1.0
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/README.en.md +1 -1
- package/README.md +2 -2
- package/package.json +1 -1
- package/types/{index-9UX4E7wG.d.ts → index-n7kSnbyZ.d.ts} +12 -11
- package/types/index.d.ts +1 -1
- package/types/react/index.d.ts +1 -1
- package/types/vue/index.d.ts +1 -1
package/README.en.md
CHANGED
|
@@ -264,7 +264,7 @@ interface BaseResponseVO {
|
|
|
264
264
|
message: string;
|
|
265
265
|
}
|
|
266
266
|
|
|
267
|
-
const request = hookFetch.create<BaseResponseVO>({
|
|
267
|
+
const request = hookFetch.create<BaseResponseVO, 'data'>({
|
|
268
268
|
baseURL: 'https://example.com',
|
|
269
269
|
headers: {
|
|
270
270
|
'Content-Type': 'application/json',
|
package/README.md
CHANGED
|
@@ -375,7 +375,7 @@ interface BaseResponseVO {
|
|
|
375
375
|
message: string;
|
|
376
376
|
}
|
|
377
377
|
|
|
378
|
-
const request = hookFetch.create<BaseResponseVO>({
|
|
378
|
+
const request = hookFetch.create<BaseResponseVO, 'data'>({
|
|
379
379
|
baseURL: 'https://example.com',
|
|
380
380
|
headers: {
|
|
381
381
|
'Content-Type': 'application/json',
|
|
@@ -392,7 +392,7 @@ interface User {
|
|
|
392
392
|
|
|
393
393
|
// 在请求中使用类型
|
|
394
394
|
const res = await request.get<User>('/users/1').json();
|
|
395
|
-
console.log(res.data); // TypeScript提供完整类型提示
|
|
395
|
+
console.log(res.data); // TypeScript 提供完整类型提示
|
|
396
396
|
```
|
|
397
397
|
|
|
398
398
|
## 完整API
|
package/package.json
CHANGED
|
@@ -23,7 +23,8 @@ declare class HookFetchRequest<T, E> implements PromiseLike<T> {
|
|
|
23
23
|
}
|
|
24
24
|
//#endregion
|
|
25
25
|
//#region src/base.d.ts
|
|
26
|
-
|
|
26
|
+
type GenericWithNull<T, R extends AnyObject | null, K extends keyof R> = R extends null ? T : Generic<Exclude<R, null>, K, T>;
|
|
27
|
+
declare class HookFetch<R extends AnyObject | null = null, K extends keyof R = never, E = AnyObject> {
|
|
27
28
|
#private;
|
|
28
29
|
constructor({
|
|
29
30
|
timeout,
|
|
@@ -42,15 +43,15 @@ declare class HookFetch<R extends AnyObject = AnyObject, K extends keyof R = 'da
|
|
|
42
43
|
qsArrayFormat,
|
|
43
44
|
withCredentials,
|
|
44
45
|
extra
|
|
45
|
-
}?: RequestOptions<P, D, E>): HookFetchRequest<
|
|
46
|
-
get<T = AnyObject, P = AnyObject>(url: string, params?: P, options?: GetOptions<P, E>): HookFetchRequest<
|
|
47
|
-
head<T = AnyObject, P = AnyObject>(url: string, params?: P, options?: HeadOptions<P, E>): HookFetchRequest<
|
|
48
|
-
options<T = AnyObject, P = AnyObject, D = AnyObject>(url: string, params?: P, options?: OptionsOptions<P, D, E>): HookFetchRequest<
|
|
49
|
-
delete<T = AnyObject, D = AnyObject, P = AnyObject>(url: string, options?: DeleteOptions<P, D, E>): HookFetchRequest<
|
|
50
|
-
post<T = AnyObject, D = AnyObject, P = AnyObject>(url: string, data?: D, options?: PostOptions<D, P, E>): HookFetchRequest<
|
|
51
|
-
upload<T = AnyObject, D = AnyObject, P = AnyObject>(url: string, data?: D, options?: PostOptions<D, P, E>): HookFetchRequest<
|
|
52
|
-
put<T = AnyObject, D = AnyObject, P = AnyObject>(url: string, data?: D, options?: PutOptions<D, P, E>): HookFetchRequest<
|
|
53
|
-
patch<T = AnyObject, D = AnyObject, P = AnyObject>(url: string, data?: D, options?: PatchOptions<D, P, E>): HookFetchRequest<
|
|
46
|
+
}?: RequestOptions<P, D, E>): HookFetchRequest<GenericWithNull<T, R, K>, E>;
|
|
47
|
+
get<T = AnyObject, P = AnyObject>(url: string, params?: P, options?: GetOptions<P, E>): HookFetchRequest<GenericWithNull<T, R, K>, E>;
|
|
48
|
+
head<T = AnyObject, P = AnyObject>(url: string, params?: P, options?: HeadOptions<P, E>): HookFetchRequest<GenericWithNull<T, R, K>, E>;
|
|
49
|
+
options<T = AnyObject, P = AnyObject, D = AnyObject>(url: string, params?: P, options?: OptionsOptions<P, D, E>): HookFetchRequest<GenericWithNull<T, R, K>, E>;
|
|
50
|
+
delete<T = AnyObject, D = AnyObject, P = AnyObject>(url: string, options?: DeleteOptions<P, D, E>): HookFetchRequest<GenericWithNull<T, R, K>, E>;
|
|
51
|
+
post<T = AnyObject, D = AnyObject, P = AnyObject>(url: string, data?: D, options?: PostOptions<D, P, E>): HookFetchRequest<GenericWithNull<T, R, K>, E>;
|
|
52
|
+
upload<T = AnyObject, D = AnyObject, P = AnyObject>(url: string, data?: D, options?: PostOptions<D, P, E>): HookFetchRequest<GenericWithNull<T, R, K>, E>;
|
|
53
|
+
put<T = AnyObject, D = AnyObject, P = AnyObject>(url: string, data?: D, options?: PutOptions<D, P, E>): HookFetchRequest<GenericWithNull<T, R, K>, E>;
|
|
54
|
+
patch<T = AnyObject, D = AnyObject, P = AnyObject>(url: string, data?: D, options?: PatchOptions<D, P, E>): HookFetchRequest<GenericWithNull<T, R, K>, E>;
|
|
54
55
|
abortAll(): void;
|
|
55
56
|
}
|
|
56
57
|
declare const useRequest: <R = AnyObject, P = AnyObject, D = AnyObject, E = AnyObject>(url: string, options?: RequestOptions<P, D, E>) => HookFetchRequest<R, E>;
|
|
@@ -64,7 +65,7 @@ declare const upload: <R = AnyObject, D = AnyObject, P = AnyObject, E = AnyObjec
|
|
|
64
65
|
declare const put: <R = AnyObject, D = AnyObject, P = AnyObject, E = AnyObject>(url: string, data?: D, options?: PutOptions<D, P, E>) => HookFetchRequest<R, E>;
|
|
65
66
|
declare const patch: <R = AnyObject, D = AnyObject, P = AnyObject, E = AnyObject>(url: string, data?: D, options?: PatchOptions<D, P, E>) => HookFetchRequest<R, E>;
|
|
66
67
|
type ExportDefault = typeof useRequest & {
|
|
67
|
-
create: <R extends AnyObject =
|
|
68
|
+
create: <R extends AnyObject | null = null, K extends keyof R = never, E = AnyObject>(options: BaseOptions) => (HookFetch<R, K, E>['request'] & HookFetch<R, K, E>);
|
|
68
69
|
get: typeof get;
|
|
69
70
|
head: typeof head;
|
|
70
71
|
options: typeof options;
|
package/types/index.d.ts
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
1
|
import { AfterResponseHandler, BaseOptions, BaseRequestOptions, BeforeRequestHandler, BeforeStreamHandler, DeleteOptions, FetchPluginContext, FetchResponseType, GetOptions, HeadOptions, HookFetchPlugin, OnErrorHandler, OnFinallyHandler, OptionProps, OptionsOptions, PatchOptions, PostOptions, PutOptions, RequestConfig, RequestMethod, RequestMethodWithBody, RequestMethodWithParams, RequestOptions, RequestUseOptions, RequestWithBodyFnOptions, RequestWithBodyOptions, RequestWithParamsFnOptions, RequestWithParamsOptions, ResponseError, ResponseErrorOptions, StreamContext, TransformStreamChunkHandler } from "./types-CAGBd7wv.js";
|
|
2
|
-
import { ContentType, Method, StatusCode, del, get, head, hookFetch, options, patch, post, put, request, upload } from "./index-
|
|
2
|
+
import { ContentType, Method, StatusCode, del, get, head, hookFetch, options, patch, post, put, request, upload } from "./index-n7kSnbyZ.js";
|
|
3
3
|
export { AfterResponseHandler, BaseOptions, BaseRequestOptions, BeforeRequestHandler, BeforeStreamHandler, ContentType, DeleteOptions, FetchPluginContext, FetchResponseType, GetOptions, HeadOptions, HookFetchPlugin, Method, OnErrorHandler, OnFinallyHandler, OptionProps, OptionsOptions, PatchOptions, PostOptions, PutOptions, RequestConfig, RequestMethod, RequestMethodWithBody, RequestMethodWithParams, RequestOptions, RequestUseOptions, RequestWithBodyFnOptions, RequestWithBodyOptions, RequestWithParamsFnOptions, RequestWithParamsOptions, ResponseError, ResponseErrorOptions, StatusCode, StreamContext, TransformStreamChunkHandler, hookFetch as default, del, get, head, options, patch, post, put, request, upload };
|
package/types/react/index.d.ts
CHANGED
package/types/vue/index.d.ts
CHANGED