@@ -20,7 +20,11 @@ import type {
20
20
CurriedGetDefaultMiddleware ,
21
21
} from './getDefaultMiddleware'
22
22
import { curryGetDefaultMiddleware } from './getDefaultMiddleware'
23
- import type { NoInfer , ExtractDispatchExtensions } from './tsHelpers'
23
+ import type {
24
+ NoInfer ,
25
+ ExtractDispatchExtensions ,
26
+ ExtractStoreExtensions ,
27
+ } from './tsHelpers'
24
28
25
29
const IS_PRODUCTION = process . env . NODE_ENV === 'production'
26
30
@@ -29,9 +33,7 @@ const IS_PRODUCTION = process.env.NODE_ENV === 'production'
29
33
*
30
34
* @public
31
35
*/
32
- export type ConfigureEnhancersCallback = (
33
- defaultEnhancers : readonly StoreEnhancer [ ]
34
- ) => StoreEnhancer [ ]
36
+ export type ConfigureEnhancersCallback < E extends Enhancers = Enhancers > = ( defaultEnhancers : E ) => E
35
37
36
38
/**
37
39
* Options for `configureStore()`.
@@ -41,7 +43,8 @@ export type ConfigureEnhancersCallback = (
41
43
export interface ConfigureStoreOptions <
42
44
S = any ,
43
45
A extends Action = AnyAction ,
44
- M extends Middlewares < S > = Middlewares < S >
46
+ M extends Middlewares < S > = Middlewares < S > ,
47
+ E extends Enhancers = Enhancers
45
48
> {
46
49
/**
47
50
* A single reducer function that will be used as the root reducer, or an
@@ -52,7 +55,7 @@ export interface ConfigureStoreOptions<
52
55
/**
53
56
* An array of Redux middleware to install. If not supplied, defaults to
54
57
* the set of middleware returned by `getDefaultMiddleware()`.
55
- *
58
+ *
56
59
* @example `middleware: (gDM) => gDM().concat(logger, apiMiddleware, yourCustomMiddleware)`
57
60
* @see https://redux-toolkit.js.org/api/getDefaultMiddleware#intended-usage
58
61
*/
@@ -92,43 +95,47 @@ export interface ConfigureStoreOptions<
92
95
* and should return a new array (such as `[applyMiddleware, offline]`).
93
96
* If you only need to add middleware, you can use the `middleware` parameter instead.
94
97
*/
95
- enhancers ?: StoreEnhancer [ ] | ConfigureEnhancersCallback
98
+ enhancers ?: E | ConfigureEnhancersCallback < E >
96
99
}
97
100
98
101
type Middlewares < S > = ReadonlyArray < Middleware < { } , S > >
99
102
103
+ type Enhancers = ReadonlyArray < StoreEnhancer >
104
+
100
105
/**
101
106
* A Redux store returned by `configureStore()`. Supports dispatching
102
107
* side-effectful _thunks_ in addition to plain actions.
103
108
*
104
109
* @public
105
110
*/
106
- export interface EnhancedStore <
111
+ export type EnhancedStore <
107
112
S = any ,
108
113
A extends Action = AnyAction ,
109
- M extends Middlewares < S > = Middlewares < S >
110
- > extends Store < S , A > {
111
- /**
112
- * The `dispatch` method of your store, enhanced by all its middlewares.
113
- *
114
- * @inheritdoc
115
- */
116
- dispatch : ExtractDispatchExtensions < M > & Dispatch < A >
117
- }
114
+ M extends Middlewares < S > = Middlewares < S > ,
115
+ E extends Enhancers = Enhancers
116
+ > = Store < S , A > & {
117
+ /**
118
+ * The `dispatch` method of your store, enhanced by all its middlewares.
119
+ *
120
+ * @inheritdoc
121
+ */
122
+ dispatch : ExtractDispatchExtensions < M > & Dispatch < A >
123
+ } & ExtractStoreExtensions < E >
118
124
119
125
/**
120
126
* A friendly abstraction over the standard Redux `createStore()` function.
121
127
*
122
- * @param config The store configuration.
128
+ * @param options The store configuration.
123
129
* @returns A configured Redux store.
124
130
*
125
131
* @public
126
132
*/
127
133
export function configureStore <
128
134
S = any ,
129
135
A extends Action = AnyAction ,
130
- M extends Middlewares < S > = [ ThunkMiddlewareFor < S > ]
131
- > ( options : ConfigureStoreOptions < S , A , M > ) : EnhancedStore < S , A , M > {
136
+ M extends Middlewares < S > = [ ThunkMiddlewareFor < S > ] ,
137
+ E extends Enhancers = [ ]
138
+ > ( options : ConfigureStoreOptions < S , A , M > ) : EnhancedStore < S , A , M , E > {
132
139
const curriedGetDefaultMiddleware = curryGetDefaultMiddleware < S > ( )
133
140
134
141
const {
@@ -182,7 +189,7 @@ export function configureStore<
182
189
} )
183
190
}
184
191
185
- let storeEnhancers : StoreEnhancer [ ] = [ middlewareEnhancer ]
192
+ let storeEnhancers : ReadonlyArray < StoreEnhancer > = [ middlewareEnhancer ]
186
193
187
194
if ( Array . isArray ( enhancers ) ) {
188
195
storeEnhancers = [ middlewareEnhancer , ...enhancers ]
0 commit comments