@@ -15,7 +15,8 @@ import {
15
15
SerializedError ,
16
16
PayloadActionCreator ,
17
17
AsyncThunk ,
18
- CaseReducer
18
+ CaseReducer ,
19
+ configureStore
19
20
} from '../../src'
20
21
21
22
function expectType < T > ( t : T ) {
@@ -515,10 +516,16 @@ const value = actionCreators.anyKey
515
516
TestArg ,
516
517
TestReturned ,
517
518
{
518
- rejectValue : TestReject
519
+ rejectValue : TestReject // this introduces a circular reference
520
+ dispatch : StoreDispatch // this introduces a circular reference
521
+ state : StoreState
519
522
}
520
523
> (
521
524
function payloadCreator ( arg , api ) {
525
+ // here would be a circular reference
526
+ expectType < StoreState > ( api . getState ( ) )
527
+ // here would be a circular reference
528
+ expectType < StoreDispatch > ( api . dispatch )
522
529
expectType < TestArg > ( arg )
523
530
expectType < ( value : TestReject ) => any > ( api . rejectWithValue )
524
531
return Promise . resolve ( { payload : 'foo' } )
@@ -544,6 +551,15 @@ const value = actionCreators.anyKey
544
551
} )
545
552
} )
546
553
554
+ // this would cause a circular reference:
555
+ // const store = configureStore({ reducer: { test: slice.reducer } })
556
+ // this is the only way to break it (could be a cast at the export from the slice file)
557
+ const testReducer = slice . reducer as Reducer < TestState >
558
+ const store = configureStore ( { reducer : { test : testReducer } } )
559
+
560
+ type StoreState = ReturnType < typeof store . getState >
561
+ type StoreDispatch = typeof store . dispatch
562
+
547
563
expectType < PayloadActionCreator < string > > ( slice . actions . normalReducer )
548
564
expectType < AsyncThunk < TestReturned , TestArg , { } > > ( slice . actions . testInfer )
549
565
expectType < AsyncThunk < TestReturned , TestArg , { rejectValue : TestReject } > > (
0 commit comments