2
2
3
3
import * as React from 'react'
4
4
import * as ReactDOM from 'react-dom'
5
- import { Store , Dispatch , configureStore } from '@reduxjs/toolkit'
5
+ import { Store , Dispatch , configureStore , AnyAction } from '@reduxjs/toolkit'
6
6
import {
7
7
connect ,
8
8
ConnectedProps ,
@@ -34,6 +34,8 @@ import {
34
34
fetchCount ,
35
35
} from './counterApp'
36
36
37
+ import { expectType } from '../typeTestHelpers'
38
+
37
39
function preTypedHooksSetup ( ) {
38
40
// Standard hooks setup
39
41
const useAppDispatch = ( ) => useDispatch < AppDispatch > ( )
@@ -147,8 +149,7 @@ function testUseSelector() {
147
149
useSelector ( selector , 'a' )
148
150
useSelector ( selector , ( l , r ) => l === r )
149
151
useSelector ( selector , ( l , r ) => {
150
- // $ExpectType { counter: number; active: string; }
151
- l
152
+ expectType < { counter : number ; active : string } > ( l )
152
153
return l === r
153
154
} )
154
155
@@ -169,12 +170,11 @@ function testUseSelector() {
169
170
170
171
const useTypedSelector : TypedUseSelectorHook < RootState > = useSelector
171
172
172
- // $ExpectType string
173
173
const r = useTypedSelector ( ( state ) => {
174
- // $ExpectType RootState
175
- state
174
+ expectType < RootState > ( state )
176
175
return state . property
177
176
} )
177
+ expectType < string > ( r )
178
178
}
179
179
180
180
function testUseStore ( ) {
@@ -188,7 +188,7 @@ function testUseStore() {
188
188
189
189
const untypedStore = useStore ( )
190
190
const state = untypedStore . getState ( )
191
- state . things . stuff . anything // any by default
191
+ expectType < unknown > ( state )
192
192
193
193
const typedStore = useStore < TypedState , TypedAction > ( )
194
194
const typedState = typedStore . getState ( )
@@ -211,18 +211,22 @@ function testCreateHookFunctions() {
211
211
> ( null as any )
212
212
213
213
// No context tests
214
- // $ExpectType () => Dispatch<AnyAction>
215
- createDispatchHook ( )
216
- // $ExpectType <Selected extends unknown>(selector: (state: any) => Selected, equalityFn?: ((previous: Selected, next: Selected) => boolean) | undefined) => Selected
217
- createSelectorHook ( )
218
- // $ExpectType () => Store<any, AnyAction>
219
- createStoreHook ( )
214
+ expectType < ( ) => Dispatch < AnyAction > > ( createDispatchHook ( ) )
215
+ expectType <
216
+ < Selected extends unknown > (
217
+ selector : ( state : any ) => Selected ,
218
+ equalityFn ?: ( ( previous : Selected , next : Selected ) => boolean ) | undefined
219
+ ) => Selected
220
+ > ( createSelectorHook ( ) )
221
+ expectType < ( ) => Store < any , AnyAction > > ( createStoreHook ( ) )
220
222
221
223
// With context tests
222
- // $ExpectType () => Dispatch<RootAction>
223
- createDispatchHook ( Context )
224
- // $ExpectType <Selected extends unknown>(selector: (state: RootState) => Selected, equalityFn?: ((previous: Selected, next: Selected) => boolean) | undefined) => Selected
225
- createSelectorHook ( Context )
226
- // $ExpectType () => Store<RootState, RootAction>
227
- createStoreHook ( Context )
224
+ expectType < ( ) => Dispatch < RootAction > > ( createDispatchHook ( Context ) )
225
+ expectType <
226
+ < Selected extends unknown > (
227
+ selector : ( state : RootState ) => Selected ,
228
+ equalityFn ?: ( ( previous : Selected , next : Selected ) => boolean ) | undefined
229
+ ) => Selected
230
+ > ( createSelectorHook ( Context ) )
231
+ expectType < ( ) => Store < RootState , RootAction > > ( createStoreHook ( Context ) )
228
232
}
0 commit comments