@@ -10,6 +10,7 @@ import type {
1010 ThunkAction ,
1111 ThunkDispatch ,
1212 ThunkMiddleware ,
13+ ThunkOverload ,
1314 UnknownAction ,
1415} from '@reduxjs/toolkit'
1516import {
@@ -150,9 +151,7 @@ describe('type tests', () => {
150151 enhancers : ( ) => [ enhancer ] ,
151152 } )
152153
153- expectTypeOf ( store . dispatch ) . toMatchTypeOf <
154- Dispatch & ThunkDispatch < number , undefined , UnknownAction >
155- > ( )
154+ expectTypeOf ( store . dispatch ) . toMatchTypeOf < Dispatch > ( )
156155
157156 configureStore ( {
158157 reducer : ( ) => 0 ,
@@ -202,9 +201,7 @@ describe('type tests', () => {
202201 . concat ( somePropertyStoreEnhancer ) ,
203202 } )
204203
205- expectTypeOf ( store3 . dispatch ) . toMatchTypeOf <
206- Dispatch & ThunkDispatch < number , undefined , UnknownAction >
207- > ( )
204+ expectTypeOf ( store3 . dispatch ) . toMatchTypeOf < Dispatch > ( )
208205
209206 expectTypeOf ( store3 . someProperty ) . toBeString ( )
210207
@@ -423,7 +420,12 @@ describe('type tests', () => {
423420 type StateA = number
424421 const reducerA = ( ) => 0
425422 const thunkA = ( ) => {
426- return ( ( ) => { } ) as any as ThunkAction < Promise < 'A' > , StateA , any , any >
423+ return ( ( ) => { } ) as any as ThunkAction <
424+ ThunkDispatch < StateA , any , any > ,
425+ StateA ,
426+ any ,
427+ Promise < 'A' >
428+ >
427429 }
428430
429431 type StateB = string
@@ -560,35 +562,35 @@ describe('type tests', () => {
560562 const store = configureStore ( { reducer : { } } )
561563 // undefined is the default value for the ThunkMiddleware extraArgument
562564 store . dispatch ( function ( ) { } as ThunkAction <
563- void ,
565+ ThunkDispatch < { } , undefined , UnknownAction > ,
564566 { } ,
565567 undefined ,
566- UnknownAction
568+ void
567569 > )
568570 // `null` for the `extra` generic was previously documented in the RTK "Advanced Tutorial", but
569571 // is a bad pattern and users should use `unknown` instead
570572 // @ts -expect-error
571573 store . dispatch ( function ( ) { } as ThunkAction <
572- void ,
574+ ThunkDispatch < { } , null , UnknownAction > ,
573575 { } ,
574576 null ,
575- UnknownAction
577+ void
576578 > )
577579 // unknown is the best way to type a ThunkAction if you do not care
578580 // about the value of the extraArgument, as it will always work with every
579581 // ThunkMiddleware, no matter the actual extraArgument type
580582 store . dispatch ( function ( ) { } as ThunkAction <
581- void ,
583+ ThunkDispatch < { } , unknown , UnknownAction > ,
582584 { } ,
583585 unknown ,
584- UnknownAction
586+ void
585587 > )
586588 // @ts -expect-error
587589 store . dispatch ( function ( ) { } as ThunkAction <
588- void ,
590+ ThunkDispatch < { } , boolean , UnknownAction > ,
589591 { } ,
590592 boolean ,
591- UnknownAction
593+ void
592594 > )
593595 } )
594596
@@ -792,7 +794,7 @@ describe('type tests', () => {
792794 // the thunk middleware type kicks in and TS thinks a plain action is being returned
793795 expectTypeOf ( store . dispatch ) . toEqualTypeOf <
794796 ( ( action : Action < 'actionListenerMiddleware/add' > ) => Unsubscribe ) &
795- ThunkDispatch < CounterState , undefined , UnknownAction > &
797+ ThunkOverload < CounterState , undefined > &
796798 Dispatch < UnknownAction >
797799 > ( )
798800
0 commit comments