@@ -531,8 +531,10 @@ export interface RemoveListenerAction<
531531}
532532
533533/**
534+ * A "pre-typed" version of `addListenerAction`, so the listener args are well-typed
535+ *
534536 * @public
535- * A "pre-typed" version of `addListenerAction`, so the listener args are well-typed * /
537+ */
536538export type TypedAddListener <
537539 StateType ,
538540 DispatchType extends ReduxDispatch = ThunkDispatch <
@@ -550,15 +552,42 @@ export type TypedAddListener<
550552 DispatchType ,
551553 ExtraArgument
552554 > & {
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+ */
553576 withTypes : <
554577 OverrideStateType extends StateType ,
555- OverrideDispatchType extends DispatchType
578+ OverrideDispatchType extends ReduxDispatch = ThunkDispatch <
579+ OverrideStateType ,
580+ unknown ,
581+ UnknownAction
582+ >
556583 > ( ) => TypedAddListener < OverrideStateType , OverrideDispatchType >
557584 }
558585
559586/**
587+ * A "pre-typed" version of `removeListenerAction`, so the listener args are well-typed
588+ *
560589 * @public
561- * A "pre-typed" version of `removeListenerAction`, so the listener args are well-typed * /
590+ */
562591export type TypedRemoveListener <
563592 StateType ,
564593 DispatchType extends ReduxDispatch = ThunkDispatch <
@@ -568,22 +597,50 @@ export type TypedRemoveListener<
568597 > ,
569598 Payload = ListenerEntry < StateType , DispatchType > ,
570599 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 <
577602 PayloadAction < Payload , T > ,
578603 StateType ,
579604 DispatchType ,
580605 any ,
581606 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+ }
583638
584639/**
640+ * A "pre-typed" version of `middleware.startListening`, so the listener args are well-typed
641+ *
585642 * @public
586- * A "pre-typed" version of `middleware.startListening`, so the listener args are well-typed * /
643+ */
587644export type TypedStartListening <
588645 StateType ,
589646 DispatchType extends ReduxDispatch = ThunkDispatch <
@@ -598,14 +655,49 @@ export type TypedStartListening<
598655 DispatchType ,
599656 ExtraArgument
600657> & {
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+ */
601686 withTypes : <
602687 OverrideStateType extends StateType ,
603- OverrideDispatchType extends DispatchType
688+ OverrideDispatchType extends ReduxDispatch = ThunkDispatch <
689+ OverrideStateType ,
690+ unknown ,
691+ UnknownAction
692+ >
604693 > ( ) => TypedStartListening < OverrideStateType , OverrideDispatchType >
605694}
606695
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+ */
609701export type TypedStopListening <
610702 StateType ,
611703 DispatchType extends ReduxDispatch = ThunkDispatch <
@@ -614,14 +706,49 @@ export type TypedStopListening<
614706 UnknownAction
615707 >
616708> = 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+ */
617737 withTypes : <
618738 OverrideStateType extends StateType ,
619- OverrideDispatchType extends DispatchType
739+ OverrideDispatchType extends ReduxDispatch = ThunkDispatch <
740+ OverrideStateType ,
741+ unknown ,
742+ UnknownAction
743+ >
620744 > ( ) => TypedStopListening < OverrideStateType , OverrideDispatchType >
621745}
622746
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+ */
625752export type TypedCreateListenerEntry <
626753 StateType ,
627754 DispatchType extends ReduxDispatch = ThunkDispatch <
@@ -634,9 +761,37 @@ export type TypedCreateListenerEntry<
634761 StateType ,
635762 DispatchType
636763> & {
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+ */
637788 withTypes : <
638789 OverrideStateType extends StateType ,
639- OverrideDispatchType extends DispatchType
790+ OverrideDispatchType extends ReduxDispatch = ThunkDispatch <
791+ OverrideStateType ,
792+ unknown ,
793+ UnknownAction
794+ >
640795 > ( ) => TypedStopListening < OverrideStateType , OverrideDispatchType >
641796}
642797
0 commit comments