Skip to content

Commit 2f50f7b

Browse files
committed
chore: test useTransform
1 parent 9ab4a98 commit 2f50f7b

File tree

1 file changed

+27
-0
lines changed

1 file changed

+27
-0
lines changed
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
import { expectTypeOf, it } from 'vitest'
2+
import { formOptions, mergeForm, useForm, useTransform } from '../src'
3+
import type { ServerFormState } from '../src'
4+
5+
it('should maintain the type of the form', () => {
6+
const state = {} as ServerFormState<any, any>
7+
8+
const formOpts = formOptions({
9+
defaultValues: {
10+
firstName: '',
11+
age: 123,
12+
} as const,
13+
})
14+
15+
function Comp() {
16+
const form = useForm({
17+
...formOpts,
18+
transform: useTransform(
19+
(baseForm) => mergeForm(baseForm, state),
20+
[state],
21+
),
22+
})
23+
24+
expectTypeOf(form.state.values.age).toEqualTypeOf<123>()
25+
expectTypeOf(form.state.values.firstName).toEqualTypeOf<''>()
26+
}
27+
})

0 commit comments

Comments
 (0)