11import { Middleware , GetState , Dispatch , Reducer , Store } from '../types' ;
22
3- export interface ThunkMiddleware < State , ExtraArgument >
4- extends Middleware < State , Reducer < State > , Thunk < State , ExtraArgument > > {
5- ( store : Store < State , Reducer < State > | Delegate < State , ExtraArgument > > ) : {
6- ( next : Dispatch < Reducer < State > , State > ) : Dispatch < Delegate < State , ExtraArgument > > ;
3+ export interface ThunkMiddleware < S , EA >
4+ extends Middleware < S , Reducer < S > , Thunk < S , EA > > {
5+ ( store : Store < S , Reducer < S > | Delegate < S , EA > > ) : {
6+ ( next : Dispatch < Reducer < S > , S > ) : Dispatch < Delegate < S , EA > > ;
77 } ;
8- withExtraArgument : < EA > ( extraArgument : EA ) => ThunkMiddleware < State , EA > ;
8+ withExtraArgument : < EA > ( extraArgument : EA ) => ThunkMiddleware < S , EA > ;
99}
1010
11- export interface Delegate < State , ExtraArgument , Return = any > {
12- ( dispatch : ThunkDispatch < State , ExtraArgument > , getState : GetState < State > , extraArgument : ExtraArgument ) : Return ;
11+ export interface Delegate < S , EA , RE = any > {
12+ ( dispatch : ThunkDispatch < S , EA > , getState : GetState < S > , extraArgument : EA ) : RE ;
1313}
1414
15- export interface Thunk < State , ExtraArgument , Return = any > {
16- ( state : State ) : Delegate < State , ExtraArgument , Return > ;
15+ export interface Thunk < S , EA , RE = any > {
16+ ( state : S ) : Delegate < S , EA , RE > ;
1717}
1818
19- export interface ThunkDispatch < State , ExtraArgument > extends Dispatch < Reducer < State > , State > {
20- < Return > ( thunk : Thunk < State , ExtraArgument , Return > ) : Return ;
19+ export interface ThunkDispatch < S , EA > extends Dispatch < Reducer < S > , S > {
20+ < Return > ( thunk : Thunk < S , EA , Return > ) : Return ;
2121}
2222
23- const thunkFactory = < State , ExtraArgument > ( extraArgument ?: ExtraArgument ) => {
23+ const thunkFactory = < S , EA > ( extraArgument ?: EA ) => {
2424 const thunk = ( store => next => reducer => {
2525 if ( typeof reducer !== 'function' ) throw new Error ( 'Thunk requires reducers as functions' ) ;
2626 const state = store . getState ( ) ;
@@ -30,7 +30,7 @@ const thunkFactory = <State, ExtraArgument>(extraArgument?: ExtraArgument) => {
3030 next ( _ => result ) ;
3131 return reducer ;
3232 }
33- } ) as ThunkMiddleware < State , ExtraArgument > ;
33+ } ) as ThunkMiddleware < S , EA > ;
3434 thunk . withExtraArgument = thunkFactory ;
3535 return thunk ;
3636} ;
0 commit comments