Skip to content
Source
Sign inSign up
TanStack/form
Open History to see the last commit

useTransform.test-d.tsx

30 lines745 Bytes

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})