@@ -531,8 +531,10 @@ export interface RemoveListenerAction<
531
531
}
532
532
533
533
/**
534
+ * A "pre-typed" version of `addListenerAction`, so the listener args are well-typed
535
+ *
534
536
* @public
535
- * A "pre-typed" version of `addListenerAction`, so the listener args are well-typed * /
537
+ */
536
538
export type TypedAddListener <
537
539
StateType ,
538
540
DispatchType extends ReduxDispatch = ThunkDispatch <
@@ -550,15 +552,42 @@ export type TypedAddListener<
550
552
DispatchType ,
551
553
ExtraArgument
552
554
> & {
555
+ /**
556
+ * Creates a "pre-typed" version of `addListener`
557
+ * where the `state` and `dispatch` types are predefined.
558
+ *
559
+ * This allows you to set the `state` and `dispatch` types once,
560
+ * eliminating the need to specify them with every `addListener` call.
561
+ *
562
+ * @returns A pre-typed `addListener` with the state and dispatch types already defined.
563
+ *
564
+ * @example
565
+ * ```ts
566
+ * import { addListener } from '@reduxjs/toolkit'
567
+ *
568
+ * export const addAppListener = addListener.withTypes<RootState, AppDispatch>()
569
+ * ```
570
+ *
571
+ * @template OverrideStateType - The specific type of state the middleware listener operates on.
572
+ * @template OverrideDispatchType - The specific type of the dispatch function.
573
+ *
574
+ * @since 2.1.0
575
+ */
553
576
withTypes : <
554
577
OverrideStateType extends StateType ,
555
- OverrideDispatchType extends DispatchType
578
+ OverrideDispatchType extends ReduxDispatch = ThunkDispatch <
579
+ OverrideStateType ,
580
+ unknown ,
581
+ UnknownAction
582
+ >
556
583
> ( ) => TypedAddListener < OverrideStateType , OverrideDispatchType >
557
584
}
558
585
559
586
/**
587
+ * A "pre-typed" version of `removeListenerAction`, so the listener args are well-typed
588
+ *
560
589
* @public
561
- * A "pre-typed" version of `removeListenerAction`, so the listener args are well-typed * /
590
+ */
562
591
export type TypedRemoveListener <
563
592
StateType ,
564
593
DispatchType extends ReduxDispatch = ThunkDispatch <
@@ -568,22 +597,50 @@ export type TypedRemoveListener<
568
597
> ,
569
598
Payload = ListenerEntry < StateType , DispatchType > ,
570
599
T extends string = 'listenerMiddleware/remove'
571
- > = BaseActionCreator < Payload , T > & {
572
- withTypes : <
573
- OverrideStateType extends StateType ,
574
- OverrideDispatchType extends DispatchType
575
- > ( ) => TypedRemoveListener < OverrideStateType , OverrideDispatchType >
576
- } & AddListenerOverloads <
600
+ > = BaseActionCreator < Payload , T > &
601
+ AddListenerOverloads <
577
602
PayloadAction < Payload , T > ,
578
603
StateType ,
579
604
DispatchType ,
580
605
any ,
581
606
UnsubscribeListenerOptions
582
- >
607
+ > & {
608
+ /**
609
+ * Creates a "pre-typed" version of `removeListener`
610
+ * where the `state` and `dispatch` types are predefined.
611
+ *
612
+ * This allows you to set the `state` and `dispatch` types once,
613
+ * eliminating the need to specify them with every `removeListener` call.
614
+ *
615
+ * @returns A pre-typed `removeListener` with the state and dispatch types already defined.
616
+ *
617
+ * @example
618
+ * ```ts
619
+ * import { removeListener } from '@reduxjs/toolkit'
620
+ *
621
+ * export const removeAppListener = removeListener.withTypes<RootState, AppDispatch>()
622
+ * ```
623
+ *
624
+ * @template OverrideStateType - The specific type of state the middleware listener operates on.
625
+ * @template OverrideDispatchType - The specific type of the dispatch function.
626
+ *
627
+ * @since 2.1.0
628
+ */
629
+ withTypes : <
630
+ OverrideStateType extends StateType ,
631
+ OverrideDispatchType extends ReduxDispatch = ThunkDispatch <
632
+ OverrideStateType ,
633
+ unknown ,
634
+ UnknownAction
635
+ >
636
+ > ( ) => TypedRemoveListener < OverrideStateType , OverrideDispatchType >
637
+ }
583
638
584
639
/**
640
+ * A "pre-typed" version of `middleware.startListening`, so the listener args are well-typed
641
+ *
585
642
* @public
586
- * A "pre-typed" version of `middleware.startListening`, so the listener args are well-typed * /
643
+ */
587
644
export type TypedStartListening <
588
645
StateType ,
589
646
DispatchType extends ReduxDispatch = ThunkDispatch <
@@ -598,14 +655,49 @@ export type TypedStartListening<
598
655
DispatchType ,
599
656
ExtraArgument
600
657
> & {
658
+ /**
659
+ * Creates a "pre-typed" version of
660
+ * {@linkcode ListenerMiddlewareInstance.startListening startListening}
661
+ * where the `state` and `dispatch` types are predefined.
662
+ *
663
+ * This allows you to set the `state` and `dispatch` types once,
664
+ * eliminating the need to specify them with every
665
+ * {@linkcode ListenerMiddlewareInstance.startListening startListening} call.
666
+ *
667
+ * @returns A pre-typed `startListening` with the state and dispatch types already defined.
668
+ *
669
+ * @example
670
+ * ```ts
671
+ * import { createListenerMiddleware } from '@reduxjs/toolkit'
672
+ *
673
+ * const listenerMiddleware = createListenerMiddleware()
674
+ *
675
+ * export const startAppListening = listenerMiddleware.startListening.withTypes<
676
+ * RootState,
677
+ * AppDispatch
678
+ * >()
679
+ * ```
680
+ *
681
+ * @template OverrideStateType - The specific type of state the middleware listener operates on.
682
+ * @template OverrideDispatchType - The specific type of the dispatch function.
683
+ *
684
+ * @since 2.1.0
685
+ */
601
686
withTypes : <
602
687
OverrideStateType extends StateType ,
603
- OverrideDispatchType extends DispatchType
688
+ OverrideDispatchType extends ReduxDispatch = ThunkDispatch <
689
+ OverrideStateType ,
690
+ unknown ,
691
+ UnknownAction
692
+ >
604
693
> ( ) => TypedStartListening < OverrideStateType , OverrideDispatchType >
605
694
}
606
695
607
- /** @public
608
- * A "pre-typed" version of `middleware.stopListening`, so the listener args are well-typed */
696
+ /**
697
+ * A "pre-typed" version of `middleware.stopListening`, so the listener args are well-typed
698
+ *
699
+ * @public
700
+ */
609
701
export type TypedStopListening <
610
702
StateType ,
611
703
DispatchType extends ReduxDispatch = ThunkDispatch <
@@ -614,14 +706,49 @@ export type TypedStopListening<
614
706
UnknownAction
615
707
>
616
708
> = RemoveListenerOverloads < StateType , DispatchType > & {
709
+ /**
710
+ * Creates a "pre-typed" version of
711
+ * {@linkcode ListenerMiddlewareInstance.stopListening stopListening}
712
+ * where the `state` and `dispatch` types are predefined.
713
+ *
714
+ * This allows you to set the `state` and `dispatch` types once,
715
+ * eliminating the need to specify them with every
716
+ * {@linkcode ListenerMiddlewareInstance.stopListening stopListening} call.
717
+ *
718
+ * @returns A pre-typed `stopListening` with the state and dispatch types already defined.
719
+ *
720
+ * @example
721
+ * ```ts
722
+ * import { createListenerMiddleware } from '@reduxjs/toolkit'
723
+ *
724
+ * const listenerMiddleware = createListenerMiddleware()
725
+ *
726
+ * export const stopAppListening = listenerMiddleware.stopListening.withTypes<
727
+ * RootState,
728
+ * AppDispatch
729
+ * >()
730
+ * ```
731
+ *
732
+ * @template OverrideStateType - The specific type of state the middleware listener operates on.
733
+ * @template OverrideDispatchType - The specific type of the dispatch function.
734
+ *
735
+ * @since 2.1.0
736
+ */
617
737
withTypes : <
618
738
OverrideStateType extends StateType ,
619
- OverrideDispatchType extends DispatchType
739
+ OverrideDispatchType extends ReduxDispatch = ThunkDispatch <
740
+ OverrideStateType ,
741
+ unknown ,
742
+ UnknownAction
743
+ >
620
744
> ( ) => TypedStopListening < OverrideStateType , OverrideDispatchType >
621
745
}
622
746
623
- /** @public
624
- * A "pre-typed" version of `createListenerEntry`, so the listener args are well-typed */
747
+ /**
748
+ * A "pre-typed" version of `createListenerEntry`, so the listener args are well-typed
749
+ *
750
+ * @public
751
+ */
625
752
export type TypedCreateListenerEntry <
626
753
StateType ,
627
754
DispatchType extends ReduxDispatch = ThunkDispatch <
@@ -634,9 +761,37 @@ export type TypedCreateListenerEntry<
634
761
StateType ,
635
762
DispatchType
636
763
> & {
764
+ /**
765
+ * Creates a "pre-typed" version of `createListenerEntry`
766
+ * where the `state` and `dispatch` types are predefined.
767
+ *
768
+ * This allows you to set the `state` and `dispatch` types once, eliminating
769
+ * the need to specify them with every `createListenerEntry` call.
770
+ *
771
+ * @returns A pre-typed `createListenerEntry` with the state and dispatch types already defined.
772
+ *
773
+ * @example
774
+ * ```ts
775
+ * import { createListenerEntry } from '@reduxjs/toolkit'
776
+ *
777
+ * export const createAppListenerEntry = createListenerEntry.withTypes<
778
+ * RootState,
779
+ * AppDispatch
780
+ * >()
781
+ * ```
782
+ *
783
+ * @template OverrideStateType - The specific type of state the middleware listener operates on.
784
+ * @template OverrideDispatchType - The specific type of the dispatch function.
785
+ *
786
+ * @since 2.1.0
787
+ */
637
788
withTypes : <
638
789
OverrideStateType extends StateType ,
639
- OverrideDispatchType extends DispatchType
790
+ OverrideDispatchType extends ReduxDispatch = ThunkDispatch <
791
+ OverrideStateType ,
792
+ unknown ,
793
+ UnknownAction
794
+ >
640
795
> ( ) => TypedStopListening < OverrideStateType , OverrideDispatchType >
641
796
}
642
797
0 commit comments