@@ -525,6 +525,38 @@ const anyAction = { type: 'foo' } as AnyAction
525
525
} )
526
526
}
527
527
528
+ {
529
+ // https://github.com/reduxjs/redux-toolkit/issues/2886
530
+ // fulfillWithValue should infer return value
531
+
532
+ const initialState = {
533
+ loading : false ,
534
+ obj : { magic : '' } ,
535
+ }
536
+
537
+ const getObj = createAsyncThunk (
538
+ 'slice/getObj' ,
539
+ async ( _ : any , { fulfillWithValue, rejectWithValue } ) => {
540
+ try {
541
+ return fulfillWithValue ( { magic : 'object' } )
542
+ } catch ( rejected : any ) {
543
+ return rejectWithValue ( rejected ?. response ?. error || rejected )
544
+ }
545
+ }
546
+ )
547
+
548
+ createSlice ( {
549
+ name : 'slice' ,
550
+ initialState,
551
+ reducers : { } ,
552
+ extraReducers : ( builder ) => {
553
+ builder . addCase ( getObj . fulfilled , ( state , action ) => {
554
+ expectExactType < { magic : string } > ( ANY ) ( action . payload )
555
+ } )
556
+ } ,
557
+ } )
558
+ }
559
+
528
560
// meta return values
529
561
{
530
562
// return values
@@ -621,8 +653,8 @@ const anyAction = { type: 'foo' } as AnyAction
621
653
622
654
// correct extra type
623
655
const { s, n } = api . extra
624
- expectExactType < string > ( s )
625
- expectExactType < number > ( n )
656
+ expectExactType < string > ( ANY ) ( s )
657
+ expectExactType < number > ( ANY ) ( n )
626
658
627
659
if ( 1 < 2 )
628
660
// @ts -expect-error
@@ -646,8 +678,8 @@ const anyAction = { type: 'foo' } as AnyAction
646
678
} )
647
679
// correct extra type
648
680
const { s, n } = api . extra
649
- expectExactType < string > ( s )
650
- expectExactType < number > ( n )
681
+ expectExactType < string > ( ANY ) ( s )
682
+ expectExactType < number > ( ANY ) ( n )
651
683
652
684
if ( 1 < 2 )
653
685
// @ts -expect-error
@@ -673,8 +705,8 @@ const anyAction = { type: 'foo' } as AnyAction
673
705
} )
674
706
// correct extra type
675
707
const { s, n } = api . extra
676
- expectExactType < string > ( s )
677
- expectExactType < number > ( n )
708
+ expectExactType < string > ( ANY ) ( s )
709
+ expectExactType < number > ( ANY ) ( n )
678
710
if ( 1 < 2 ) return api . rejectWithValue ( 5 )
679
711
if ( 1 < 2 )
680
712
// @ts -expect-error
0 commit comments