@@ -10,6 +10,7 @@ import type {
10
10
ThunkAction ,
11
11
ThunkDispatch ,
12
12
ThunkMiddleware ,
13
+ ThunkOverload ,
13
14
UnknownAction ,
14
15
} from '@reduxjs/toolkit'
15
16
import {
@@ -150,9 +151,7 @@ describe('type tests', () => {
150
151
enhancers : ( ) => [ enhancer ] ,
151
152
} )
152
153
153
- expectTypeOf ( store . dispatch ) . toMatchTypeOf <
154
- Dispatch & ThunkDispatch < number , undefined , UnknownAction >
155
- > ( )
154
+ expectTypeOf ( store . dispatch ) . toMatchTypeOf < Dispatch > ( )
156
155
157
156
configureStore ( {
158
157
reducer : ( ) => 0 ,
@@ -202,9 +201,7 @@ describe('type tests', () => {
202
201
. concat ( somePropertyStoreEnhancer ) ,
203
202
} )
204
203
205
- expectTypeOf ( store3 . dispatch ) . toMatchTypeOf <
206
- Dispatch & ThunkDispatch < number , undefined , UnknownAction >
207
- > ( )
204
+ expectTypeOf ( store3 . dispatch ) . toMatchTypeOf < Dispatch > ( )
208
205
209
206
expectTypeOf ( store3 . someProperty ) . toBeString ( )
210
207
@@ -423,7 +420,12 @@ describe('type tests', () => {
423
420
type StateA = number
424
421
const reducerA = ( ) => 0
425
422
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
+ >
427
429
}
428
430
429
431
type StateB = string
@@ -560,35 +562,35 @@ describe('type tests', () => {
560
562
const store = configureStore ( { reducer : { } } )
561
563
// undefined is the default value for the ThunkMiddleware extraArgument
562
564
store . dispatch ( function ( ) { } as ThunkAction <
563
- void ,
565
+ ThunkDispatch < { } , undefined , UnknownAction > ,
564
566
{ } ,
565
567
undefined ,
566
- UnknownAction
568
+ void
567
569
> )
568
570
// `null` for the `extra` generic was previously documented in the RTK "Advanced Tutorial", but
569
571
// is a bad pattern and users should use `unknown` instead
570
572
// @ts -expect-error
571
573
store . dispatch ( function ( ) { } as ThunkAction <
572
- void ,
574
+ ThunkDispatch < { } , null , UnknownAction > ,
573
575
{ } ,
574
576
null ,
575
- UnknownAction
577
+ void
576
578
> )
577
579
// unknown is the best way to type a ThunkAction if you do not care
578
580
// about the value of the extraArgument, as it will always work with every
579
581
// ThunkMiddleware, no matter the actual extraArgument type
580
582
store . dispatch ( function ( ) { } as ThunkAction <
581
- void ,
583
+ ThunkDispatch < { } , unknown , UnknownAction > ,
582
584
{ } ,
583
585
unknown ,
584
- UnknownAction
586
+ void
585
587
> )
586
588
// @ts -expect-error
587
589
store . dispatch ( function ( ) { } as ThunkAction <
588
- void ,
590
+ ThunkDispatch < { } , boolean , UnknownAction > ,
589
591
{ } ,
590
592
boolean ,
591
- UnknownAction
593
+ void
592
594
> )
593
595
} )
594
596
@@ -792,7 +794,7 @@ describe('type tests', () => {
792
794
// the thunk middleware type kicks in and TS thinks a plain action is being returned
793
795
expectTypeOf ( store . dispatch ) . toEqualTypeOf <
794
796
( ( action : Action < 'actionListenerMiddleware/add' > ) => Unsubscribe ) &
795
- ThunkDispatch < CounterState , undefined , UnknownAction > &
797
+ ThunkOverload < CounterState , undefined > &
796
798
Dispatch < UnknownAction >
797
799
> ( )
798
800
0 commit comments