Skip to content

Commit f3af0b9

Browse files
committed
Add hooks.withTypes.test-d.tsx type test file
1 parent 1b2b8f1 commit f3af0b9

File tree

2 files changed

+47
-42
lines changed

2 files changed

+47
-42
lines changed

test/typetests/hooks.tsx

Lines changed: 2 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,10 @@ import {
1818
useStore,
1919
} from '../../src/index'
2020

21-
import type { AppDispatch, AppStore, RootState } from './counterApp'
21+
import type { AppDispatch, RootState } from './counterApp'
2222
import { incrementAsync } from './counterApp'
2323

24-
import { exactType, expectExactType, expectType } from '../typeTestHelpers'
24+
import { expectExactType, expectType } from '../typeTestHelpers'
2525

2626
function preTypedHooksSetup() {
2727
// Standard hooks setup
@@ -237,43 +237,3 @@ function testCreateHookFunctions() {
237237
>(createSelectorHook(Context))
238238
expectType<() => Store<RootState, RootAction>>(createStoreHook(Context))
239239
}
240-
241-
function preTypedHooksSetupWithTypes() {
242-
const useAppDispatch = useDispatch.withTypes<AppDispatch>()
243-
244-
const useAppSelector = useSelector.withTypes<RootState>()
245-
246-
const useAppStore = useStore.withTypes<AppStore>()
247-
248-
function CounterComponent() {
249-
useAppSelector((state) => state.counter)
250-
251-
const dispatch = useAppDispatch()
252-
253-
expectExactType<AppDispatch>(dispatch)
254-
255-
const store = useAppStore()
256-
257-
expectExactType<AppStore>(store)
258-
259-
expectExactType<AppDispatch>(store.dispatch)
260-
261-
const state = store.getState()
262-
263-
expectExactType<RootState>(state)
264-
265-
expectExactType<number>(state.counter)
266-
267-
store.dispatch(incrementAsync(1))
268-
269-
exactType(store.dispatch, dispatch)
270-
271-
return (
272-
<button
273-
onClick={() => {
274-
dispatch(incrementAsync(1))
275-
}}
276-
/>
277-
)
278-
}
279-
}
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
import * as React from 'react'
2+
import { useDispatch, useSelector, useStore } from '../../src/index'
3+
import { exactType, expectExactType } from '../typeTestHelpers'
4+
import type { AppDispatch, AppStore, RootState } from './counterApp'
5+
import { incrementAsync } from './counterApp'
6+
7+
function preTypedHooksSetupWithTypes() {
8+
const useAppDispatch = useDispatch.withTypes<AppDispatch>()
9+
10+
const useAppSelector = useSelector.withTypes<RootState>()
11+
12+
const useAppStore = useStore.withTypes<AppStore>()
13+
14+
function CounterComponent() {
15+
useAppSelector((state) => state.counter)
16+
17+
const dispatch = useAppDispatch()
18+
19+
expectExactType<AppDispatch>(dispatch)
20+
21+
const store = useAppStore()
22+
23+
expectExactType<AppStore>(store)
24+
25+
expectExactType<AppDispatch>(store.dispatch)
26+
27+
const state = store.getState()
28+
29+
expectExactType<RootState>(state)
30+
31+
expectExactType<number>(state.counter)
32+
33+
store.dispatch(incrementAsync(1))
34+
35+
exactType(store.dispatch, dispatch)
36+
37+
return (
38+
<button
39+
onClick={() => {
40+
dispatch(incrementAsync(1))
41+
}}
42+
/>
43+
)
44+
}
45+
}

0 commit comments

Comments
 (0)