-
-
Notifications
You must be signed in to change notification settings - Fork 342
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: maintain the form types when transforming with useTransform hook (…
- Loading branch information
1 parent
354f63a
commit b998045
Showing
2 changed files
with
32 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
import { assertType, it } from 'vitest' | ||
import { formOptions, mergeForm, useForm, useTransform } from '../src' | ||
import { type ServerFormState } from '../src/nextjs/types' | ||
|
||
it('should maintain the type of the form', () => { | ||
const state = {} as ServerFormState<any> | ||
|
||
const formOpts = formOptions({ | ||
defaultValues: { | ||
firstName: '', | ||
age: 123, | ||
} as const, | ||
}) | ||
|
||
function Comp() { | ||
const form = useForm({ | ||
...formOpts, | ||
transform: useTransform( | ||
(baseForm) => mergeForm(baseForm, state), | ||
[state], | ||
), | ||
}) | ||
|
||
assertType<123>(form.state.values.age) | ||
assertType<string>(form.state.values.firstName) | ||
|
||
// @ts-expect-error this should be a number | ||
form.state.values.age = 'age' | ||
} | ||
}) |