22
33import * as React from 'react'
44import * as ReactDOM from 'react-dom'
5- import { Store , Dispatch , configureStore } from '@reduxjs/toolkit'
5+ import { Store , Dispatch , configureStore , AnyAction } from '@reduxjs/toolkit'
66import {
77 connect ,
88 ConnectedProps ,
@@ -34,6 +34,8 @@ import {
3434 fetchCount ,
3535} from './counterApp'
3636
37+ import { expectType } from '../typeTestHelpers'
38+
3739function preTypedHooksSetup ( ) {
3840 // Standard hooks setup
3941 const useAppDispatch = ( ) => useDispatch < AppDispatch > ( )
@@ -147,8 +149,7 @@ function testUseSelector() {
147149 useSelector ( selector , 'a' )
148150 useSelector ( selector , ( l , r ) => l === r )
149151 useSelector ( selector , ( l , r ) => {
150- // $ExpectType { counter: number; active: string; }
151- l
152+ expectType < { counter : number ; active : string } > ( l )
152153 return l === r
153154 } )
154155
@@ -169,12 +170,11 @@ function testUseSelector() {
169170
170171 const useTypedSelector : TypedUseSelectorHook < RootState > = useSelector
171172
172- // $ExpectType string
173173 const r = useTypedSelector ( ( state ) => {
174- // $ExpectType RootState
175- state
174+ expectType < RootState > ( state )
176175 return state . property
177176 } )
177+ expectType < string > ( r )
178178}
179179
180180function testUseStore ( ) {
@@ -188,7 +188,7 @@ function testUseStore() {
188188
189189 const untypedStore = useStore ( )
190190 const state = untypedStore . getState ( )
191- state . things . stuff . anything // any by default
191+ expectType < unknown > ( state )
192192
193193 const typedStore = useStore < TypedState , TypedAction > ( )
194194 const typedState = typedStore . getState ( )
@@ -211,18 +211,22 @@ function testCreateHookFunctions() {
211211 > ( null as any )
212212
213213 // 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 ( ) )
220222
221223 // 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 ) )
228232}
0 commit comments