@@ -623,6 +623,29 @@ const anyAction = { type: 'foo' } as AnyAction
623
623
return test1 + test2
624
624
} )
625
625
626
+ const thunk3 = typedCAT <
627
+ number ,
628
+ string ,
629
+ // @ts -expect-error TODO
630
+ // right now this still errors because
631
+ // it does not contain `state` and `dispatch`
632
+ {
633
+ rejectValue : string
634
+ }
635
+ > ( 'foo' , ( arg , api ) => {
636
+ // correct getState Type
637
+ const test1 : number = api . getState ( ) . foo . value
638
+ // correct dispatch type
639
+ const test2 : number = api . dispatch (
640
+ ( dispatch , getState ) => getState ( ) . foo . value
641
+ )
642
+ if ( 1 < 2 ) {
643
+ // TODO: @ts -expect-error
644
+ return api . rejectWithValue ( 5 )
645
+ }
646
+ return api . rejectWithValue ( 5 )
647
+ } )
648
+
626
649
const slice = createSlice ( {
627
650
name : 'foo' ,
628
651
initialState : { value : 0 } ,
@@ -635,6 +658,10 @@ const anyAction = { type: 'foo' } as AnyAction
635
658
. addCase ( thunk2 . fulfilled , ( state , action ) => {
636
659
state . value += action . payload
637
660
} )
661
+ . addCase ( thunk3 . rejected , ( state , action ) => {
662
+ // @ts -expect-error TODO does not have the right type yet because the config was incomplete
663
+ state . value += action . payload
664
+ } )
638
665
} ,
639
666
} )
640
667
0 commit comments