@@ -13,6 +13,7 @@ import {
1313 configureStore ,
1414 getDefaultMiddleware ,
1515 createSlice ,
16+ ConfigureStoreOptions ,
1617} from '@reduxjs/toolkit'
1718import type { ThunkMiddleware , ThunkAction , ThunkDispatch } from 'redux-thunk'
1819import thunk from 'redux-thunk'
@@ -304,6 +305,18 @@ const _anyMiddleware: any = () => () => () => {}
304305 // @ts -expect-error
305306 const result2 : string = store . dispatch ( 5 )
306307 }
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+ }
307320 /**
308321 * Test: multiple custom middleware
309322 */
@@ -473,6 +486,32 @@ const _anyMiddleware: any = () => () => () => {}
473486 expectNotAny ( store . dispatch )
474487 }
475488
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+
476515 {
477516 interface CounterState {
478517 value : number
0 commit comments