Skip to content

Commit bafe55e

Browse files
committed
Add typetests
1 parent fc3954a commit bafe55e

File tree

1 file changed

+15
-1
lines changed

1 file changed

+15
-1
lines changed

test/typetests/hooks.tsx

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ import {
3434
fetchCount,
3535
} from './counterApp'
3636

37-
import { expectType } from '../typeTestHelpers'
37+
import { expectType, expectExactType } from '../typeTestHelpers'
3838

3939
function preTypedHooksSetup() {
4040
// Standard hooks setup
@@ -87,6 +87,20 @@ function testShallowEqual() {
8787
shallowEqual({ test: 'test' }, { test: 'test' })
8888
shallowEqual({ test: 'test' }, 'a')
8989
const x: boolean = shallowEqual('a', 'a')
90+
91+
type TestState = { stateProp: string }
92+
93+
// Additionally, it should infer its type from arguments and not become `any`
94+
const selected1 = useSelector(
95+
(state: TestState) => state.stateProp,
96+
shallowEqual
97+
)
98+
expectExactType<string>(selected1)
99+
100+
const useAppSelector: TypedUseSelectorHook<TestState> = useSelector
101+
102+
const selected2 = useAppSelector((state) => state.stateProp, shallowEqual)
103+
expectExactType<string>(selected2)
90104
}
91105

92106
function testUseDispatch() {

0 commit comments

Comments
 (0)