11import type {
2- Action as ReduxAction ,
3- UnknownAction ,
4- Dispatch as ReduxDispatch ,
5- Middleware ,
6- } from 'redux'
7- import type { TSHelpersExtractDispatchExtensions } from '@reduxjs/toolkit'
2+ DynamicMiddlewareInstance ,
3+ GetDispatch ,
4+ GetState ,
5+ MiddlewareApiConfig ,
6+ TSHelpersExtractDispatchExtensions ,
7+ } from '@reduxjs/toolkit'
88import { createDynamicMiddleware as cDM } from '@reduxjs/toolkit'
9+ import type { Context } from 'react'
910import type { ReactReduxContextValue } from 'react-redux'
1011import {
12+ createDispatchHook ,
1113 ReactReduxContext ,
1214 useDispatch as useDefaultDispatch ,
13- createDispatchHook ,
1415} from 'react-redux'
15- import type { Context } from 'react'
16- import type {
17- DynamicMiddlewareInstance ,
18- GetDispatch ,
19- GetState ,
20- MiddlewareApiConfig ,
21- } from '@reduxjs/toolkit'
16+ import type { Action , Dispatch , Middleware , UnknownAction } from 'redux'
2217
2318export type UseDispatchWithMiddlewareHook <
24- Middlewares extends Middleware < any , State , Dispatch > [ ] = [ ] ,
19+ Middlewares extends Middleware < any , State , DispatchType > [ ] = [ ] ,
2520 State = any ,
26- Dispatch extends ReduxDispatch < UnknownAction > = ReduxDispatch < UnknownAction > ,
27- > = ( ) => TSHelpersExtractDispatchExtensions < Middlewares > & Dispatch
21+ DispatchType extends Dispatch < UnknownAction > = Dispatch < UnknownAction > ,
22+ > = ( ) => TSHelpersExtractDispatchExtensions < Middlewares > & DispatchType
2823
2924export type CreateDispatchWithMiddlewareHook <
3025 State = any ,
31- Dispatch extends ReduxDispatch < UnknownAction > = ReduxDispatch < UnknownAction > ,
26+ DispatchType extends Dispatch < UnknownAction > = Dispatch < UnknownAction > ,
3227> = {
3328 <
3429 Middlewares extends [
35- Middleware < any , State , Dispatch > ,
36- ...Middleware < any , State , Dispatch > [ ] ,
30+ Middleware < any , State , DispatchType > ,
31+ ...Middleware < any , State , DispatchType > [ ] ,
3732 ] ,
3833 > (
3934 ...middlewares : Middlewares
40- ) : UseDispatchWithMiddlewareHook < Middlewares , State , Dispatch >
35+ ) : UseDispatchWithMiddlewareHook < Middlewares , State , DispatchType >
4136 withTypes <
4237 MiddlewareConfig extends MiddlewareApiConfig ,
4338 > ( ) : CreateDispatchWithMiddlewareHook <
@@ -46,43 +41,43 @@ export type CreateDispatchWithMiddlewareHook<
4641 >
4742}
4843
49- type ActionFromDispatch < Dispatch extends ReduxDispatch < ReduxAction > > =
50- Dispatch extends ReduxDispatch < infer Action > ? Action : never
44+ type ActionFromDispatch < DispatchType extends Dispatch < Action > > =
45+ DispatchType extends Dispatch < infer Action > ? Action : never
5146
5247interface ReactDynamicMiddlewareInstance <
5348 State = any ,
54- Dispatch extends ReduxDispatch < UnknownAction > = ReduxDispatch < UnknownAction > ,
55- > extends DynamicMiddlewareInstance < State , Dispatch > {
49+ DispatchType extends Dispatch < UnknownAction > = Dispatch < UnknownAction > ,
50+ > extends DynamicMiddlewareInstance < State , DispatchType > {
5651 createDispatchWithMiddlewareHookFactory : (
5752 context ?: Context < ReactReduxContextValue <
5853 State ,
59- ActionFromDispatch < Dispatch >
54+ ActionFromDispatch < DispatchType >
6055 > | null > ,
61- ) => CreateDispatchWithMiddlewareHook < State , Dispatch >
56+ ) => CreateDispatchWithMiddlewareHook < State , DispatchType >
6257 createDispatchWithMiddlewareHook : CreateDispatchWithMiddlewareHook <
6358 State ,
64- Dispatch
59+ DispatchType
6560 >
6661}
6762
6863export const createDynamicMiddleware = <
6964 State = any ,
70- Dispatch extends ReduxDispatch < UnknownAction > = ReduxDispatch < UnknownAction > ,
71- > ( ) : ReactDynamicMiddlewareInstance < State , Dispatch > => {
72- const instance = cDM < State , Dispatch > ( )
65+ DispatchType extends Dispatch < UnknownAction > = Dispatch < UnknownAction > ,
66+ > ( ) : ReactDynamicMiddlewareInstance < State , DispatchType > => {
67+ const instance = cDM < State , DispatchType > ( )
7368 const createDispatchWithMiddlewareHookFactory = (
7469 // @ts -ignore
7570 context : Context < ReactReduxContextValue <
7671 State ,
77- ActionFromDispatch < Dispatch >
72+ ActionFromDispatch < DispatchType >
7873 > | null > = ReactReduxContext ,
7974 ) => {
8075 const useDispatch =
8176 context === ReactReduxContext
8277 ? useDefaultDispatch
8378 : createDispatchHook ( context )
8479 function createDispatchWithMiddlewareHook <
85- Middlewares extends Middleware < any , State , Dispatch > [ ] ,
80+ Middlewares extends Middleware < any , State , DispatchType > [ ] ,
8681 > ( ...middlewares : Middlewares ) {
8782 instance . addMiddleware ( ...middlewares )
8883 return useDispatch
@@ -91,7 +86,7 @@ export const createDynamicMiddleware = <
9186 createDispatchWithMiddlewareHook
9287 return createDispatchWithMiddlewareHook as CreateDispatchWithMiddlewareHook <
9388 State ,
94- Dispatch
89+ DispatchType
9590 >
9691 }
9792
0 commit comments