@@ -5,8 +5,9 @@ import type {
5
5
Middleware ,
6
6
Store ,
7
7
Reducer ,
8
- MiddlewareArray ,
9
- ThunkMiddleware ,
8
+ EnhancerArray ,
9
+ StoreEnhancer ,
10
+ ThunkDispatch ,
10
11
} from '@reduxjs/toolkit'
11
12
import { configureStore } from '@reduxjs/toolkit'
12
13
import { setupListeners } from '@reduxjs/toolkit/query'
@@ -206,41 +207,40 @@ export function setupApiStore<
206
207
}
207
208
} = { }
208
209
) {
210
+ type State = {
211
+ api : ReturnType < A [ 'reducer' ] >
212
+ } & {
213
+ [ K in keyof R ] : ReturnType < R [ K ] >
214
+ }
215
+ type StoreType = EnhancedStore <
216
+ State ,
217
+ AnyAction ,
218
+ EnhancerArray <
219
+ [ StoreEnhancer < { dispatch : ThunkDispatch < State , unknown , AnyAction > } > ]
220
+ >
221
+ >
222
+
209
223
const { middleware } = options
210
224
const getStore = ( ) =>
211
225
configureStore ( {
212
226
reducer : { api : api . reducer , ...extraReducers } ,
213
- middleware : (
214
- gdm
215
- ) : MiddlewareArray < [ ThunkMiddleware < { api : any } > , ...Middleware [ ] ] > => {
227
+ middleware : ( gdm ) => {
216
228
const tempMiddleware = gdm ( {
217
229
serializableCheck : false ,
218
230
immutableCheck : false ,
219
231
} ) . concat ( api . middleware )
220
232
221
233
return tempMiddleware
222
234
. concat ( ...( middleware ?. concat ?? [ ] ) )
223
- . prepend ( ...( middleware ?. prepend ?? [ ] ) ) as typeof tempMiddleware
235
+ . prepend ( ...( middleware ?. prepend ?? [ ] ) ) as any
224
236
} ,
225
237
enhancers : ( gde ) =>
226
238
gde ( {
227
239
autoBatch : false ,
228
240
} ) ,
229
- } )
230
-
231
- type StoreType = EnhancedStore <
232
- {
233
- api : ReturnType < A [ 'reducer' ] >
234
- } & {
235
- [ K in keyof R ] : ReturnType < R [ K ] >
236
- } ,
237
- AnyAction ,
238
- ReturnType < typeof getStore > extends EnhancedStore < any , any , infer M >
239
- ? M
240
- : never
241
- >
241
+ } ) as StoreType
242
242
243
- const initialStore = getStore ( ) as StoreType
243
+ const initialStore = getStore ( )
244
244
const refObj = {
245
245
api,
246
246
store : initialStore ,
@@ -250,7 +250,7 @@ export function setupApiStore<
250
250
251
251
if ( ! options . withoutTestLifecycles ) {
252
252
beforeEach ( ( ) => {
253
- const store = getStore ( ) as StoreType
253
+ const store = getStore ( )
254
254
refObj . store = store
255
255
refObj . wrapper = withProvider ( store )
256
256
if ( ! options . withoutListeners ) {
0 commit comments