@@ -13,6 +13,7 @@ import {
13
13
configureStore ,
14
14
getDefaultMiddleware ,
15
15
createSlice ,
16
+ ConfigureStoreOptions ,
16
17
} from '@reduxjs/toolkit'
17
18
import type { ThunkMiddleware , ThunkAction , ThunkDispatch } from 'redux-thunk'
18
19
import thunk from 'redux-thunk'
@@ -304,6 +305,18 @@ const _anyMiddleware: any = () => () => () => {}
304
305
// @ts -expect-error
305
306
const result2 : string = store . dispatch ( 5 )
306
307
}
308
+ /**
309
+ * Test: read-only middleware tuple
310
+ */
311
+ {
312
+ const store = configureStore ( {
313
+ reducer : reducerA ,
314
+ middleware : [ ] as any as readonly [ Middleware < ( a : StateA ) => boolean , StateA > ] ,
315
+ } )
316
+ const result : boolean = store . dispatch ( 5 )
317
+ // @ts -expect-error
318
+ const result2 : string = store . dispatch ( 5 )
319
+ }
307
320
/**
308
321
* Test: multiple custom middleware
309
322
*/
@@ -473,6 +486,32 @@ const _anyMiddleware: any = () => () => () => {}
473
486
expectNotAny ( store . dispatch )
474
487
}
475
488
489
+ /**
490
+ * Test: decorated `configureStore` won't make `dispatch` `never`
491
+ */
492
+ {
493
+ const someSlice = createSlice ( {
494
+ name : 'something' ,
495
+ initialState : null as any ,
496
+ reducers : {
497
+ set ( state ) {
498
+ return state ;
499
+ } ,
500
+ } ,
501
+ } ) ;
502
+
503
+ function configureMyStore < S > ( options : Omit < ConfigureStoreOptions < S > , 'reducer' > ) {
504
+ return configureStore ( {
505
+ ...options ,
506
+ reducer : someSlice . reducer ,
507
+ } ) ;
508
+ }
509
+
510
+ const store = configureMyStore ( { } ) ;
511
+
512
+ expectType < Function > ( store . dispatch ) ;
513
+ }
514
+
476
515
{
477
516
interface CounterState {
478
517
value : number
0 commit comments