@@ -506,11 +506,12 @@ export type RemoveListenerOverloads<
506
506
unknown ,
507
507
UnknownAction
508
508
> ,
509
+ ExtraArgument = unknown ,
509
510
> = AddListenerOverloads <
510
511
boolean ,
511
512
StateType ,
512
513
DispatchType ,
513
- any ,
514
+ ExtraArgument ,
514
515
UnsubscribeListenerOptions
515
516
>
516
517
@@ -551,22 +552,23 @@ export type TypedAddListener<
551
552
> & {
552
553
/**
553
554
* Creates a "pre-typed" version of `addListener`
554
- * where the `state` and `dispatch ` types are predefined.
555
+ * where the `state`, `dispatch` and `extra ` types are predefined.
555
556
*
556
- * This allows you to set the `state` and `dispatch ` types once,
557
+ * This allows you to set the `state`, `dispatch` and `extra ` types once,
557
558
* eliminating the need to specify them with every `addListener` call.
558
559
*
559
- * @returns A pre-typed `addListener` with the state and dispatch types already defined.
560
+ * @returns A pre-typed `addListener` with the state, dispatch and extra types already defined.
560
561
*
561
562
* @example
562
563
* ```ts
563
564
* import { addListener } from '@reduxjs/toolkit'
564
565
*
565
- * export const addAppListener = addListener.withTypes<RootState, AppDispatch>()
566
+ * export const addAppListener = addListener.withTypes<RootState, AppDispatch, ExtraArguments >()
566
567
* ```
567
568
*
568
569
* @template OverrideStateType - The specific type of state the middleware listener operates on.
569
570
* @template OverrideDispatchType - The specific type of the dispatch function.
571
+ * @template OverrideExtraArgument - The specific type of the extra object.
570
572
*
571
573
* @since 2.1.0
572
574
*/
@@ -576,8 +578,9 @@ export type TypedAddListener<
576
578
OverrideStateType ,
577
579
unknown ,
578
580
UnknownAction
579
- > ,
580
- > ( ) => TypedAddListener < OverrideStateType , OverrideDispatchType >
581
+ > ,
582
+ OverrideExtraArgument = unknown ,
583
+ > ( ) => TypedAddListener < OverrideStateType , OverrideDispatchType , OverrideExtraArgument >
581
584
}
582
585
583
586
/**
@@ -592,34 +595,41 @@ export type TypedRemoveListener<
592
595
unknown ,
593
596
UnknownAction
594
597
> ,
598
+ ExtraArgument = unknown ,
595
599
Payload = ListenerEntry < StateType , DispatchType > ,
596
600
T extends string = 'listenerMiddleware/remove' ,
597
601
> = BaseActionCreator < Payload , T > &
598
602
AddListenerOverloads <
599
603
PayloadAction < Payload , T > ,
600
604
StateType ,
601
605
DispatchType ,
602
- any ,
606
+ ExtraArgument ,
603
607
UnsubscribeListenerOptions
604
608
> & {
605
609
/**
606
610
* Creates a "pre-typed" version of `removeListener`
607
- * where the `state` and `dispatch ` types are predefined.
611
+ * where the `state`, `dispatch` and `extra ` types are predefined.
608
612
*
609
- * This allows you to set the `state` and `dispatch ` types once,
613
+ * This allows you to set the `state`, `dispatch` and `extra ` types once,
610
614
* eliminating the need to specify them with every `removeListener` call.
611
615
*
612
- * @returns A pre-typed `removeListener` with the state and dispatch types already defined.
616
+ * @returns A pre-typed `removeListener` with the state, dispatch and extra
617
+ * types already defined.
613
618
*
614
619
* @example
615
620
* ```ts
616
621
* import { removeListener } from '@reduxjs/toolkit'
617
622
*
618
- * export const removeAppListener = removeListener.withTypes<RootState, AppDispatch>()
623
+ * export const removeAppListener = removeListener.withTypes<
624
+ * RootState,
625
+ * AppDispatch,
626
+ * ExtraArguments
627
+ * >()
619
628
* ```
620
629
*
621
630
* @template OverrideStateType - The specific type of state the middleware listener operates on.
622
631
* @template OverrideDispatchType - The specific type of the dispatch function.
632
+ * @template OverrideExtraArgument - The specific type of the extra object.
623
633
*
624
634
* @since 2.1.0
625
635
*/
@@ -630,7 +640,8 @@ export type TypedRemoveListener<
630
640
unknown ,
631
641
UnknownAction
632
642
> ,
633
- > ( ) => TypedRemoveListener < OverrideStateType , OverrideDispatchType >
643
+ OverrideExtraArgument = unknown ,
644
+ > ( ) => TypedRemoveListener < OverrideStateType , OverrideDispatchType , OverrideExtraArgument >
634
645
}
635
646
636
647
/**
@@ -655,13 +666,13 @@ export type TypedStartListening<
655
666
/**
656
667
* Creates a "pre-typed" version of
657
668
* {@linkcode ListenerMiddlewareInstance.startListening startListening}
658
- * where the `state` and `dispatch ` types are predefined.
669
+ * where the `state`, `dispatch` and `extra ` types are predefined.
659
670
*
660
- * This allows you to set the `state` and `dispatch ` types once,
671
+ * This allows you to set the `state`, `dispatch` and `extra ` types once,
661
672
* eliminating the need to specify them with every
662
673
* {@linkcode ListenerMiddlewareInstance.startListening startListening} call.
663
674
*
664
- * @returns A pre-typed `startListening` with the state and dispatch types already defined.
675
+ * @returns A pre-typed `startListening` with the state, dispatch and extra types already defined.
665
676
*
666
677
* @example
667
678
* ```ts
@@ -671,12 +682,14 @@ export type TypedStartListening<
671
682
*
672
683
* export const startAppListening = listenerMiddleware.startListening.withTypes<
673
684
* RootState,
674
- * AppDispatch
685
+ * AppDispatch,
686
+ * ExtraArguments
675
687
* >()
676
688
* ```
677
689
*
678
690
* @template OverrideStateType - The specific type of state the middleware listener operates on.
679
691
* @template OverrideDispatchType - The specific type of the dispatch function.
692
+ * @template OverrideExtraArgument - The specific type of the extra object.
680
693
*
681
694
* @since 2.1.0
682
695
*/
@@ -687,7 +700,8 @@ export type TypedStartListening<
687
700
unknown ,
688
701
UnknownAction
689
702
> ,
690
- > ( ) => TypedStartListening < OverrideStateType , OverrideDispatchType >
703
+ OverrideExtraArgument = unknown ,
704
+ > ( ) => TypedStartListening < OverrideStateType , OverrideDispatchType , OverrideExtraArgument >
691
705
}
692
706
693
707
/**
@@ -702,17 +716,18 @@ export type TypedStopListening<
702
716
unknown ,
703
717
UnknownAction
704
718
> ,
705
- > = RemoveListenerOverloads < StateType , DispatchType > & {
719
+ ExtraArgument = unknown ,
720
+ > = RemoveListenerOverloads < StateType , DispatchType , ExtraArgument > & {
706
721
/**
707
722
* Creates a "pre-typed" version of
708
723
* {@linkcode ListenerMiddlewareInstance.stopListening stopListening}
709
- * where the `state` and `dispatch ` types are predefined.
724
+ * where the `state`, `dispatch` and `extra ` types are predefined.
710
725
*
711
- * This allows you to set the `state` and `dispatch ` types once,
726
+ * This allows you to set the `state`, `dispatch` and `extra ` types once,
712
727
* eliminating the need to specify them with every
713
728
* {@linkcode ListenerMiddlewareInstance.stopListening stopListening} call.
714
729
*
715
- * @returns A pre-typed `stopListening` with the state and dispatch types already defined.
730
+ * @returns A pre-typed `stopListening` with the state, dispatch and extra types already defined.
716
731
*
717
732
* @example
718
733
* ```ts
@@ -722,12 +737,14 @@ export type TypedStopListening<
722
737
*
723
738
* export const stopAppListening = listenerMiddleware.stopListening.withTypes<
724
739
* RootState,
725
- * AppDispatch
740
+ * AppDispatch,
741
+ * ExtraArguments
726
742
* >()
727
743
* ```
728
744
*
729
745
* @template OverrideStateType - The specific type of state the middleware listener operates on.
730
746
* @template OverrideDispatchType - The specific type of the dispatch function.
747
+ * @template OverrideExtraArgument - The specific type of the extra object.
731
748
*
732
749
* @since 2.1.0
733
750
*/
@@ -738,7 +755,8 @@ export type TypedStopListening<
738
755
unknown ,
739
756
UnknownAction
740
757
> ,
741
- > ( ) => TypedStopListening < OverrideStateType , OverrideDispatchType >
758
+ OverrideExtraArgument = unknown ,
759
+ > ( ) => TypedStopListening < OverrideStateType , OverrideDispatchType , OverrideExtraArgument >
742
760
}
743
761
744
762
/**
@@ -753,32 +771,37 @@ export type TypedCreateListenerEntry<
753
771
unknown ,
754
772
UnknownAction
755
773
> ,
774
+ ExtraArgument = unknown ,
756
775
> = AddListenerOverloads <
757
776
ListenerEntry < StateType , DispatchType > ,
758
777
StateType ,
759
- DispatchType
778
+ DispatchType ,
779
+ ExtraArgument
760
780
> & {
761
781
/**
762
782
* Creates a "pre-typed" version of `createListenerEntry`
763
- * where the `state` and `dispatch ` types are predefined.
783
+ * where the `state`, `dispatch` and `extra ` types are predefined.
764
784
*
765
- * This allows you to set the `state` and `dispatch ` types once, eliminating
785
+ * This allows you to set the `state`, `dispatch` and `extra ` types once, eliminating
766
786
* the need to specify them with every `createListenerEntry` call.
767
787
*
768
- * @returns A pre-typed `createListenerEntry` with the state and dispatch types already defined.
788
+ * @returns A pre-typed `createListenerEntry` with the state, dispatch and extra
789
+ * types already defined.
769
790
*
770
791
* @example
771
792
* ```ts
772
793
* import { createListenerEntry } from '@reduxjs/toolkit'
773
794
*
774
795
* export const createAppListenerEntry = createListenerEntry.withTypes<
775
796
* RootState,
776
- * AppDispatch
797
+ * AppDispatch,
798
+ * ExtraArguments
777
799
* >()
778
800
* ```
779
801
*
780
802
* @template OverrideStateType - The specific type of state the middleware listener operates on.
781
803
* @template OverrideDispatchType - The specific type of the dispatch function.
804
+ * @template OverrideExtraArgument - The specific type of the extra object.
782
805
*
783
806
* @since 2.1.0
784
807
*/
@@ -789,7 +812,8 @@ export type TypedCreateListenerEntry<
789
812
unknown ,
790
813
UnknownAction
791
814
> ,
792
- > ( ) => TypedStopListening < OverrideStateType , OverrideDispatchType >
815
+ OverrideExtraArgument = unknown ,
816
+ > ( ) => TypedStopListening < OverrideStateType , OverrideDispatchType , OverrideExtraArgument >
793
817
}
794
818
795
819
/**
0 commit comments