@@ -11,11 +11,12 @@ import {
11
11
connect ,
12
12
createSelectorHook ,
13
13
} from '../../src/index'
14
- import type { FunctionComponent } from 'react'
15
14
import { useReduxContext } from '../../src/hooks/useReduxContext'
15
+ import type { FunctionComponent , DispatchWithoutAction , ReactNode } from 'react'
16
16
import type { Store , AnyAction } from 'redux'
17
17
import type { ProviderProps , TypedUseSelectorHook } from '../../src/'
18
18
import type { Subscription } from '../../src/utils/Subscription'
19
+ import type { ReactReduxContextValue } from '../../src/components/Context'
19
20
20
21
describe ( 'React' , ( ) => {
21
22
describe ( 'hooks' , ( ) => {
@@ -24,7 +25,7 @@ describe('React', () => {
24
25
count : number
25
26
}
26
27
let normalStore : Store < NormalStateType , AnyAction >
27
- let renderedItems = [ ]
28
+ let renderedItems : any [ ] = [ ]
28
29
type RootState = ReturnType < typeof normalStore . getState >
29
30
let useNormalSelector : TypedUseSelectorHook < RootState > = useSelector
30
31
@@ -80,7 +81,7 @@ describe('React', () => {
80
81
81
82
describe ( 'lifecycle interactions' , ( ) => {
82
83
it ( 'always uses the latest state' , ( ) => {
83
- const store = createStore ( ( c : number ) : number => c + 1 , - 1 )
84
+ const store = createStore ( ( c : number = 1 ) : number => c + 1 , - 1 )
84
85
85
86
const Comp = ( ) => {
86
87
const selector = useCallback ( ( c : number ) : number => c + 1 , [ ] )
@@ -106,7 +107,7 @@ describe('React', () => {
106
107
let rootSubscription : Subscription
107
108
108
109
const Parent = ( ) => {
109
- const { subscription } = useReduxContext ( )
110
+ const { subscription } = useReduxContext ( ) as ReactReduxContextValue
110
111
rootSubscription = subscription
111
112
const count = useNormalSelector ( ( s ) => s . count )
112
113
return count === 1 ? < Child /> : null
@@ -122,19 +123,19 @@ describe('React', () => {
122
123
< Parent />
123
124
</ ProviderMock >
124
125
)
125
-
126
+ // @ts -ignore ts(2454)
126
127
expect ( rootSubscription . getListeners ( ) . get ( ) . length ) . toBe ( 1 )
127
128
128
129
normalStore . dispatch ( { type : '' } )
129
-
130
+ // @ts -ignore ts(2454)
130
131
expect ( rootSubscription . getListeners ( ) . get ( ) . length ) . toBe ( 2 )
131
132
} )
132
133
133
134
it ( 'unsubscribes when the component is unmounted' , ( ) => {
134
135
let rootSubscription : Subscription
135
136
136
137
const Parent = ( ) => {
137
- const { subscription } = useReduxContext ( )
138
+ const { subscription } = useReduxContext ( ) as ReactReduxContextValue
138
139
rootSubscription = subscription
139
140
const count = useNormalSelector ( ( s ) => s . count )
140
141
return count === 0 ? < Child /> : null
@@ -150,11 +151,11 @@ describe('React', () => {
150
151
< Parent />
151
152
</ ProviderMock >
152
153
)
153
-
154
+ // @ts -ignore ts(2454)
154
155
expect ( rootSubscription . getListeners ( ) . get ( ) . length ) . toBe ( 2 )
155
156
156
157
normalStore . dispatch ( { type : '' } )
157
-
158
+ // @ts -ignore ts(2454)
158
159
expect ( rootSubscription . getListeners ( ) . get ( ) . length ) . toBe ( 1 )
159
160
} )
160
161
@@ -183,7 +184,7 @@ describe('React', () => {
183
184
} )
184
185
185
186
it ( 'works properly with memoized selector with dispatch in Child useLayoutEffect' , ( ) => {
186
- const store = createStore ( ( c : number ) : number => c + 1 , - 1 )
187
+ const store = createStore ( ( c : number = 1 ) : number => c + 1 , - 1 )
187
188
188
189
const Comp = ( ) => {
189
190
const selector = useCallback ( ( c : number ) : number => c , [ ] )
@@ -282,7 +283,7 @@ describe('React', () => {
282
283
283
284
it ( 'uses the latest selector' , ( ) => {
284
285
let selectorId = 0
285
- let forceRender
286
+ let forceRender : DispatchWithoutAction
286
287
287
288
const Comp = ( ) => {
288
289
const [ , f ] = useReducer ( ( c ) => c + 1 , 0 )
@@ -301,15 +302,19 @@ describe('React', () => {
301
302
302
303
expect ( renderedItems ) . toEqual ( [ 0 ] )
303
304
304
- rtl . act ( forceRender )
305
+ rtl . act ( ( ) => {
306
+ forceRender ( )
307
+ } )
305
308
expect ( renderedItems ) . toEqual ( [ 0 , 1 ] )
306
309
307
310
rtl . act ( ( ) => {
308
311
normalStore . dispatch ( { type : '' } )
309
312
} )
310
313
expect ( renderedItems ) . toEqual ( [ 0 , 1 ] )
311
314
312
- rtl . act ( forceRender )
315
+ rtl . act ( ( ) => {
316
+ forceRender ( )
317
+ } )
313
318
expect ( renderedItems ) . toEqual ( [ 0 , 1 , 2 ] )
314
319
} )
315
320
@@ -503,8 +508,8 @@ describe('React', () => {
503
508
} )
504
509
505
510
describe ( 'createSelectorHook' , ( ) => {
506
- let defaultStore
507
- let customStore
511
+ let defaultStore : Store
512
+ let customStore : Store
508
513
type StateType = {
509
514
count : number
510
515
}
@@ -519,7 +524,8 @@ describe('React', () => {
519
524
} )
520
525
521
526
it ( 'subscribes to the correct store' , ( ) => {
522
- const nestedContext = React . createContext ( null )
527
+ const nestedContext =
528
+ React . createContext < ReactReduxContextValue | null > ( null )
523
529
const useCustomSelector = createSelectorHook ( nestedContext )
524
530
let defaultCount = null
525
531
let customCount = null
@@ -531,7 +537,10 @@ describe('React', () => {
531
537
defaultCount = count
532
538
return < > { children } </ >
533
539
}
534
- const DisplayCustomCount = ( { children = null } ) => {
540
+ interface DisplayCustomCountType {
541
+ children : ReactNode
542
+ }
543
+ const DisplayCustomCount = ( { children } : DisplayCustomCountType ) => {
535
544
const count = useCustomSelector < StateType > ( getCount )
536
545
customCount = count
537
546
return < > { children } </ >
0 commit comments