Skip to content

Commit

Permalink
chore(tests): add test for useAtom types (#2503)
Browse files Browse the repository at this point in the history
  • Loading branch information
dai-shi authored Apr 16, 2024
1 parent c71d062 commit 8f0b8ec
Showing 1 changed file with 17 additions and 1 deletion.
18 changes: 17 additions & 1 deletion tests/react/types.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@ it('useAtom should handle inference of atoms (#1831 #1387)', () => {
age: atom(0),
checked: atom(false),
}

const useField = <T extends keyof typeof fieldAtoms>(prop: T) => {
return useAtom(fieldAtoms[prop])
}
Expand All @@ -50,6 +49,23 @@ it('useAtom should handle inference of atoms (#1831 #1387)', () => {
Component
})

it('useAtom should handle inference of read-only atoms', () => {
const fieldAtoms = {
username: atom(() => ''),
age: atom(() => 0),
checked: atom(() => false),
}
const useField = <T extends keyof typeof fieldAtoms>(prop: T) => {
return useAtom(fieldAtoms[prop])
}
function Component() {
expectType<[string, never]>(useField('username'))
expectType<[number, never]>(useField('age'))
expectType<[boolean, never]>(useField('checked'))
}
Component
})

it('useAtom should handle primitive atom with one type argeument', () => {
const countAtom = atom(0)
function Component() {
Expand Down

0 comments on commit 8f0b8ec

Please sign in to comment.