@@ -76,8 +76,14 @@ describe('React', () => {
76
76
type : string
77
77
body : any
78
78
}
79
- function stringBuilder ( prev = '' , action : ActionType ) {
80
- return action . type === 'APPEND' ? prev + action . body : prev
79
+ interface StringState {
80
+ string : string
81
+ }
82
+
83
+ function stringBuilder ( state = { string : '' } , action : ActionType ) {
84
+ return action . type === 'APPEND'
85
+ ? { string : state . string + action . body }
86
+ : state
81
87
}
82
88
83
89
afterEach ( ( ) => rtl . cleanup ( ) )
@@ -155,9 +161,9 @@ describe('React', () => {
155
161
return < Passthrough { ...this . props } />
156
162
}
157
163
}
158
- const ConnectedContainer = connect ( ( state ) => ( { string : state } ) ) (
159
- Container
160
- )
164
+ const ConnectedContainer = connect ( ( state : StringState ) => ( {
165
+ string : state . string ,
166
+ } ) ) ( Container )
161
167
162
168
const tester = rtl . render (
163
169
< ProviderMock store = { store } >
@@ -192,9 +198,9 @@ describe('React', () => {
192
198
TStateProps ,
193
199
unknown ,
194
200
unknown ,
195
- string
201
+ StringState
196
202
> ( ( state ) => ( {
197
- string : state ,
203
+ string : state . string ,
198
204
} ) ) ( Container )
199
205
200
206
const spy = jest . spyOn ( console , 'error' ) . mockImplementation ( ( ) => { } )
@@ -236,9 +242,9 @@ describe('React', () => {
236
242
TStateProps ,
237
243
unknown ,
238
244
unknown ,
239
- string
245
+ StringState
240
246
> ( ( state ) => ( {
241
- string : state ,
247
+ string : state . string ,
242
248
} ) ) ( Container )
243
249
244
250
const spy = jest . spyOn ( console , 'error' ) . mockImplementation ( ( ) => { } )
@@ -529,7 +535,7 @@ describe('React', () => {
529
535
}
530
536
531
537
const ConnectedInner = connect (
532
- ( state ) => ( { stateThing : state } ) ,
538
+ ( state : StringState ) => ( { stateThing : state . string } ) ,
533
539
{ doSomething } ,
534
540
( stateProps , actionProps , parentProps : InnerPropsType ) => ( {
535
541
...stateProps ,
@@ -1196,8 +1202,8 @@ describe('React', () => {
1196
1202
ChildrenPropsType ,
1197
1203
unknown ,
1198
1204
unknown ,
1199
- string
1200
- > ( ( state ) => ( { state } ) ) ( Child )
1205
+ StringState
1206
+ > ( ( state ) => ( { state : state . string } ) ) ( Child )
1201
1207
1202
1208
const { unmount } = rtl . render (
1203
1209
< ProviderMock store = { store } >
@@ -1477,9 +1483,9 @@ describe('React', () => {
1477
1483
TStateProps ,
1478
1484
TDispatchProps ,
1479
1485
{ } ,
1480
- string
1486
+ StringState
1481
1487
> (
1482
- ( state ) => ( { string : state } ) ,
1488
+ ( state ) => ( { string : state . string } ) ,
1483
1489
( dispatch ) => ( { dispatch } )
1484
1490
) ( Container )
1485
1491
@@ -1538,7 +1544,7 @@ describe('React', () => {
1538
1544
}
1539
1545
type TOwnProps = ContainerPropsType
1540
1546
type TMergedProps = TOwnProps & TDispatchProps & TStateProps
1541
- type RootState = string
1547
+ type RootState = StringState
1542
1548
1543
1549
class Container extends Component < TMergedProps > {
1544
1550
render ( ) {
@@ -1552,7 +1558,7 @@ describe('React', () => {
1552
1558
TMergedProps ,
1553
1559
RootState
1554
1560
> (
1555
- ( state ) => ( { string : state } ) ,
1561
+ ( state ) => ( { string : state . string } ) ,
1556
1562
( dispatch : ReduxDispatch ) => ( { dispatch } ) ,
1557
1563
(
1558
1564
stateProps : { string : string } ,
@@ -1705,9 +1711,9 @@ describe('React', () => {
1705
1711
return < Passthrough { ...this . props } />
1706
1712
}
1707
1713
}
1708
- const ConnectedContainer = connect ( ( state ) => {
1714
+ const ConnectedContainer = connect ( ( state : StringState ) => {
1709
1715
mapStateCalls ++
1710
- return state === 'aaa' ? { change : 1 } : { }
1716
+ return state . string === 'aaa' ? { change : 1 } : { }
1711
1717
} ) ( Container )
1712
1718
1713
1719
rtl . render (
@@ -2927,7 +2933,7 @@ describe('React', () => {
2927
2933
}
2928
2934
2929
2935
const ConnectedContainerA = connect (
2930
- ( state ) => ( { string : state } ) ,
2936
+ ( state : StringState ) => ( { string : state . string } ) ,
2931
2937
( ) => ( { } ) ,
2932
2938
( ) => ( { } ) ,
2933
2939
// The `pure` option has been removed
@@ -2942,7 +2948,7 @@ describe('React', () => {
2942
2948
}
2943
2949
2944
2950
const ConnectedContainerB = connect (
2945
- ( state ) => ( { string : state } ) ,
2951
+ ( state : StringState ) => ( { string : state . string } ) ,
2946
2952
( ) => ( { } ) ,
2947
2953
( ) => ( { } ) ,
2948
2954
// The `pure` option has been removed
@@ -2968,7 +2974,7 @@ describe('React', () => {
2968
2974
2969
2975
describe ( 'Subscription and update timing correctness' , ( ) => {
2970
2976
it ( 'should pass state consistently to mapState' , ( ) => {
2971
- type RootStateType = string
2977
+ type RootStateType = StringState
2972
2978
const store : Store = createStore ( stringBuilder )
2973
2979
2974
2980
rtl . act ( ( ) => {
@@ -2999,7 +3005,7 @@ describe('React', () => {
2999
3005
ContainerNoDisPatch ,
3000
3006
ContainerOwnProps ,
3001
3007
RootStateType
3002
- > ( ( state ) => ( { state } ) ) ( Container )
3008
+ > ( ( state ) => ( { state : state . string } ) ) ( Container )
3003
3009
3004
3010
const childCalls : any [ ] = [ ]
3005
3011
@@ -3020,9 +3026,9 @@ describe('React', () => {
3020
3026
RootStateType
3021
3027
> ( ( state , parentProps ) => {
3022
3028
childMapStateInvokes ++
3023
- childCalls . push ( [ state , parentProps . parentState ] )
3029
+ childCalls . push ( [ state . string , parentProps . parentState ] )
3024
3030
// The state from parent props should always be consistent with the current state
3025
- expect ( state ) . toEqual ( parentProps . parentState )
3031
+ expect ( state . string ) . toEqual ( parentProps . parentState )
3026
3032
return { }
3027
3033
} ) ( ChildContainer )
3028
3034
0 commit comments