1
- /* eslint-disable @typescript-eslint/no-unused-vars */
2
1
import {
3
2
Alova ,
4
3
AlovaCompleteEvent ,
@@ -472,18 +471,18 @@ type SilentQueueMap = Record<string, SilentMethod[]>;
472
471
/**
473
472
* useCaptcha配置
474
473
*/
475
- type CaptchaHookConfig < S , E , R , T , RC , RE , RH > = {
474
+ type CaptchaHookConfig < S , E , R , T , RC , RE , RH , ARG extends any [ ] > = {
476
475
/**
477
476
* 初始倒计时,当验证码发送成功时将会以此数据来开始倒计时
478
477
* @default 60
479
478
*/
480
479
initialCountdown ?: number ;
481
- } & RequestHookConfig < S , E , R , T , RC , RE , RH > ;
480
+ } & RequestHookConfig < S , E , R , T , RC , RE , RH , ARG > ;
482
481
483
482
/**
484
483
* useCaptcha返回值
485
484
*/
486
- type CaptchaReturnType < S , E , R , T , RC , RE , RH > = UseHookReturnType < S , E , R , T , RC , RE , RH > & {
485
+ type CaptchaReturnType < S , E , R , T , RC , RE , RH , ARG extends any [ ] > = UseHookReturnType < S , E , R , T , RC , RE , RH , ARG > & {
487
486
/**
488
487
* 当前倒计时,每秒-1,当倒计时到0时可再次发送验证码
489
488
*/
@@ -572,7 +571,7 @@ type FormReturnType<S, E, R, T, RC, RE, RH, F> = UseHookReturnType<S, E, R, T, R
572
571
/**
573
572
* useRetriableRequest配置
574
573
*/
575
- type RetriableHookConfig < S , E , R , T , RC , RE , RH > = {
574
+ type RetriableHookConfig < S , E , R , T , RC , RE , RH , ARG extends any [ ] > = {
576
575
/**
577
576
* 最大重试次数,也可以设置为返回 boolean 值的函数,来动态判断是否继续重试。
578
577
* @default 3
@@ -583,12 +582,12 @@ type RetriableHookConfig<S, E, R, T, RC, RE, RH> = {
583
582
* 避让策略
584
583
*/
585
584
backoff ?: BackoffPolicy ;
586
- } & RequestHookConfig < S , E , R , T , RC , RE , RH > ;
585
+ } & RequestHookConfig < S , E , R , T , RC , RE , RH , ARG > ;
587
586
588
587
/**
589
588
* useRetriableRequest onRetry回调事件实例
590
589
*/
591
- interface RetriableRetryEvent < S , E , R , T , RC , RE , RH > extends AlovaEvent < S , E , R , T , RC , RE , RH > {
590
+ interface RetriableRetryEvent < S , E , R , T , RC , RE , RH , ARG extends any [ ] > extends AlovaEvent < S , E , R , T , RC , RE , RH , ARG > {
592
591
/**
593
592
* 当前的重试次数
594
593
*/
@@ -602,7 +601,7 @@ interface RetriableRetryEvent<S, E, R, T, RC, RE, RH> extends AlovaEvent<S, E, R
602
601
/**
603
602
* useRetriableRequest onFail回调事件实例
604
603
*/
605
- interface RetriableFailEvent < S , E , R , T , RC , RE , RH > extends AlovaErrorEvent < S , E , R , T , RC , RE , RH > {
604
+ interface RetriableFailEvent < S , E , R , T , RC , RE , RH , ARG extends any [ ] > extends AlovaErrorEvent < S , E , R , T , RC , RE , RH , ARG > {
606
605
/**
607
606
* 失败时的重试次数
608
607
*/
@@ -611,7 +610,7 @@ interface RetriableFailEvent<S, E, R, T, RC, RE, RH> extends AlovaErrorEvent<S,
611
610
/**
612
611
* useRetriableRequest返回值
613
612
*/
614
- type RetriableReturnType < S , E , R , T , RC , RE , RH > = UseHookReturnType < S , E , R , T , RC , RE , RH > & {
613
+ type RetriableReturnType < S , E , R , T , RC , RE , RH , ARG extends any [ ] > = UseHookReturnType < S , E , R , T , RC , RE , RH , ARG > & {
615
614
/**
616
615
* 停止重试,只在重试期间调用有效
617
616
* 停止后将立即触发onFail事件
@@ -624,7 +623,7 @@ type RetriableReturnType<S, E, R, T, RC, RE, RH> = UseHookReturnType<S, E, R, T,
624
623
* 它们将在重试发起后触发
625
624
* @param handler 重试事件回调
626
625
*/
627
- onRetry ( handler : ( event : RetriableRetryEvent < S , E , R , T , RC , RE , RH > ) => void ) : void ;
626
+ onRetry ( handler : ( event : RetriableRetryEvent < S , E , R , T , RC , RE , RH , ARG > ) => void ) : void ;
628
627
629
628
/**
630
629
* 失败事件绑定
@@ -635,7 +634,7 @@ type RetriableReturnType<S, E, R, T, RC, RE, RH> = UseHookReturnType<S, E, R, T,
635
634
*
636
635
* @param handler 失败事件回调
637
636
*/
638
- onFail ( handler : ( event : RetriableFailEvent < S , E , R , T , RC , RE , RH > ) => void ) : void ;
637
+ onFail ( handler : ( event : RetriableFailEvent < S , E , R , T , RC , RE , RH , ARG > ) => void ) : void ;
639
638
} ;
640
639
641
640
// middlewares
@@ -650,14 +649,14 @@ interface Actions {
650
649
* @param id 委托者id
651
650
* @returns alova中间件函数
652
651
*/
653
- type ActionDelegationMiddleware = ( id : string | number | symbol ) => < S , E , R , T , RC , RE , RH > (
652
+ type ActionDelegationMiddleware = ( id : string | number | symbol ) => < S , E , R , T , RC , RE , RH , ARG extends any [ ] > (
654
653
context : (
655
- | AlovaFrontMiddlewareContext < S , E , R , T , RC , RE , RH >
656
- | AlovaFetcherMiddlewareContext < S , E , R , T , RC , RE , RH >
654
+ | AlovaFrontMiddlewareContext < S , E , R , T , RC , RE , RH , ARG >
655
+ | AlovaFetcherMiddlewareContext < S , E , R , T , RC , RE , RH , ARG >
657
656
) & {
658
657
delegatingActions ?: Actions ;
659
658
} ,
660
- next : AlovaGuardNext < S , E , R , T , RC , RE , RH >
659
+ next : AlovaGuardNext < S , E , R , T , RC , RE , RH , ARG >
661
660
) => Promise < any > ;
662
661
663
662
/**
@@ -810,7 +809,7 @@ type AlovaRequestAdapterUnified<
810
809
/**
811
810
* useAutoRequest配置
812
811
*/
813
- type AutoRequestHookConfig < S , E , R , T , RC , RE , RH > = {
812
+ type AutoRequestHookConfig < S , E , R , T , RC , RE , RH , ARG extends any [ ] > = {
814
813
/**
815
814
* 轮询事件,单位ms,0表示不开启
816
815
* @default 0
@@ -836,7 +835,7 @@ type AutoRequestHookConfig<S, E, R, T, RC, RE, RH> = {
836
835
* @default 1000
837
836
*/
838
837
throttle ?: number ;
839
- } & RequestHookConfig < S , E , R , T , RC , RE , RH > ;
838
+ } & RequestHookConfig < S , E , R , T , RC , RE , RH , ARG > ;
840
839
841
840
const enum SSEHookReadyState {
842
841
CONNECTING = 0 ,
@@ -859,9 +858,9 @@ type SSEOnMessageTrigger<Data, S, E, R, T, RC, RE, RH> = (
859
858
event : AlovaSSEMessageEvent < Data , S , E , R , T , RC , RE , RH >
860
859
) => void ;
861
860
type SSEOnErrorTrigger < S , E , R , T , RC , RE , RH > = ( event : AlovaSSEErrorEvent < S , E , R , T , RC , RE , RH > ) => void ;
862
- type SSEOn < S , E , R , T , RC , RE , RH > = (
861
+ type SSEOn < S , E , R , T , RC , RE , RH , Data > = (
863
862
eventName : string ,
864
- handler : ( event : AlovaSSEMessageEvent < S , E , R , T , RC , RE , RH > ) => void
863
+ handler : ( event : AlovaSSEMessageEvent < Data , S , E , R , T , RC , RE , RH > ) => void
865
864
) => ( ) => void ;
866
865
867
866
type NotifyHandler = ( ) => void ;
@@ -904,7 +903,7 @@ type SSEHookConfig = {
904
903
/**
905
904
* useSSE() 返回类型
906
905
*/
907
- type SSEReturnType < S , Data > = {
906
+ type SSEReturnType < S , Data , E , R , T , RC , RE , RH > = {
908
907
readyState : ExportedType < SSEHookReadyState , S > ;
909
908
data : ExportedType < Data | undefined , S > ;
910
909
eventSource : ExportedType < EventSource | undefined , S > ;
@@ -922,33 +921,35 @@ type SSEReturnType<S, Data> = {
922
921
* @param callback 回调函数
923
922
* @returns 取消注册函数
924
923
*/
925
- onOpen ( callback : SSEOnOpenTrigger ) : ( ) => void ;
924
+ onOpen ( callback : SSEOnOpenTrigger < S , E , R , T , RC , RE , RH > ) : ( ) => void ;
926
925
927
926
/**
928
927
* 注册 EventSource message 的回调函数
929
928
* @param callback 回调函数
930
929
* @returns 取消注册函数
931
930
*/
932
- onMessage < T = Data > ( callback : SSEOnMessageTrigger < T > ) : ( ) => void ;
931
+ onMessage < D = Data > ( callback : SSEOnMessageTrigger < D , S , E , R , T , RC , RE , RH > ) : ( ) => void ;
933
932
934
933
/**
935
934
* 注册 EventSource error 的回调函数
936
935
* @param callback 回调函数
937
936
* @returns 取消注册函数
938
937
*/
939
- onError ( callback : SSEOnErrorTrigger ) : ( ) => void ;
938
+ onError ( callback : SSEOnErrorTrigger < S , E , R , T , RC , RE , RH > ) : ( ) => void ;
940
939
941
940
/**
942
941
* @param eventName 事件名称,默认存在 `open` | `error` | `message`
943
942
* @param handler 事件处理器
944
943
*/
945
- on : SSEOn ;
944
+ on : SSEOn < S , E , R , T , RC , RE , RH , Data > ;
946
945
} ;
947
946
948
- type AnyFn < T = Any > = ( ...args : any [ ] ) => T ;
947
+ type AnyFn < T = any > = ( ...args : any [ ] ) => T ;
949
948
950
949
type UsePromiseReturnType < T > = {
951
950
promise : Promise < T > ;
952
951
resolve : ( value : T | PromiseLike < T > ) => void ;
953
952
reject : ( reason ?: any ) => void ;
954
953
} ;
954
+
955
+ type FetchRequestInit = Omit < RequestInit , 'body' | 'headers' | 'method' > ;
0 commit comments