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

useTransform.test-d.tsx

27 lines688 Bytes

1import { expectTypeOf, it } from 'vitest'
2import { formOptions, mergeForm, useForm, useTransform } from '../src'
3import type { ServerFormState } from '../src'
4​
5it('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})