@@ -10,10 +10,11 @@ import {
10
10
AnyAction ,
11
11
StoreEnhancer ,
12
12
Store ,
13
- DeepPartial
13
+ DeepPartial ,
14
+ Dispatch
14
15
} from 'redux'
15
16
import { composeWithDevTools } from 'redux-devtools-extension'
16
- import thunk from 'redux-thunk'
17
+ import thunk , { ThunkDispatch , ThunkMiddleware } from 'redux-thunk'
17
18
import createImmutableStateInvariantMiddleware from 'redux-immutable-state-invariant'
18
19
import createSerializableStateInvariantMiddleware from './serializableStateInvariantMiddleware'
19
20
@@ -28,10 +29,10 @@ const IS_PRODUCTION = process.env.NODE_ENV === 'production'
28
29
*
29
30
* @return The default middleware used by `configureStore()`.
30
31
*/
31
- export function getDefaultMiddleware (
32
+ export function getDefaultMiddleware < S = any , A extends Action = AnyAction > (
32
33
isProduction = IS_PRODUCTION
33
- ) : Middleware [ ] {
34
- let middlewareArray : Middleware [ ] = [ thunk ]
34
+ ) : [ ThunkMiddleware < S , A > , ... Middleware < { } , S > [ ] ] {
35
+ let middlewareArray : [ ThunkMiddleware < S , A > , ... Middleware < { } , S > [ ] ] = [ thunk ]
35
36
36
37
if ( ! isProduction ) {
37
38
middlewareArray = [
@@ -58,7 +59,7 @@ export interface ConfigureStoreOptions<S = any, A extends Action = AnyAction> {
58
59
* An array of Redux middleware to install. If not supplied, defaults to
59
60
* the set of middleware returned by `getDefaultMiddleware()`.
60
61
*/
61
- middleware ?: Middleware [ ]
62
+ middleware ?: Middleware < { } , S > [ ]
62
63
63
64
/**
64
65
* Whether to enable Redux DevTools integration. Defaults to `true`.
@@ -85,6 +86,15 @@ export interface ConfigureStoreOptions<S = any, A extends Action = AnyAction> {
85
86
enhancers ?: StoreEnhancer [ ]
86
87
}
87
88
89
+ /**
90
+ * A Redux store returned by `configureStore()`. Supports dispatching
91
+ * side-effectful _thunks_ in addition to plain actions.
92
+ */
93
+ export interface EnhancedStore < S = any , A extends Action = AnyAction >
94
+ extends Store < S , A > {
95
+ dispatch : ThunkDispatch < S , any , A >
96
+ }
97
+
88
98
/**
89
99
* A friendly abstraction over the standard Redux `createStore()` function.
90
100
*
@@ -93,7 +103,7 @@ export interface ConfigureStoreOptions<S = any, A extends Action = AnyAction> {
93
103
*/
94
104
export function configureStore < S = any , A extends Action = AnyAction > (
95
105
options : ConfigureStoreOptions < S , A >
96
- ) : Store < S , A > {
106
+ ) : EnhancedStore < S , A > {
97
107
const {
98
108
reducer = undefined ,
99
109
middleware = getDefaultMiddleware ( ) ,
@@ -134,11 +144,9 @@ export function configureStore<S = any, A extends Action = AnyAction>(
134
144
135
145
const composedEnhancer = finalCompose ( ...storeEnhancers ) as StoreEnhancer
136
146
137
- const store : Store < S , A > = createStore (
147
+ return createStore (
138
148
rootReducer ,
139
149
preloadedState as DeepPartial < S > ,
140
150
composedEnhancer
141
151
)
142
-
143
- return store
144
152
}
0 commit comments