Open History to see the last commit
1import { assertType, it } from 'vitest'
2import { formOptions, mergeForm, useForm, useTransform } from '../src'
3import type { ServerFormState } from '../src/nextjs/types'
4β
5it('should maintain the type of the form', () => {
6 const state = {} as ServerFormState<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 assertType<123>(form.state.values.age)
25 assertType<string>(form.state.values.firstName)
26β
27 // @ts-expect-error this should be a number
28 form.state.values.age = 'age'
29 }
30})