Skip to content

Commit

Permalink
Add typetests
Browse files Browse the repository at this point in the history
  • Loading branch information
markerikson committed Nov 4, 2022
1 parent fc3954a commit bafe55e
Showing 1 changed file with 15 additions and 1 deletion.
16 changes: 15 additions & 1 deletion test/typetests/hooks.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ import {
fetchCount,
} from './counterApp'

import { expectType } from '../typeTestHelpers'
import { expectType, expectExactType } from '../typeTestHelpers'

function preTypedHooksSetup() {
// Standard hooks setup
Expand Down Expand Up @@ -87,6 +87,20 @@ function testShallowEqual() {
shallowEqual({ test: 'test' }, { test: 'test' })
shallowEqual({ test: 'test' }, 'a')
const x: boolean = shallowEqual('a', 'a')

type TestState = { stateProp: string }

// Additionally, it should infer its type from arguments and not become `any`
const selected1 = useSelector(
(state: TestState) => state.stateProp,
shallowEqual
)
expectExactType<string>(selected1)

const useAppSelector: TypedUseSelectorHook<TestState> = useSelector

const selected2 = useAppSelector((state) => state.stateProp, shallowEqual)
expectExactType<string>(selected2)
}

function testUseDispatch() {
Expand Down

0 comments on commit bafe55e

Please sign in to comment.