-
-
Notifications
You must be signed in to change notification settings - Fork 528
Description
Describe the bug
Previously with v0.42.x the types of useForm
(react hook) and FormApi
(core class) had 2 generic types, with only 1 being required:
TFormData,
TFormValidator extends Validator<TFormData, unknown> | undefined = undefined,
Starting 0.43.0 however this has changed to 9 required generic types:
TFormData,
TOnMount extends undefined | FormValidateOrFn<TFormData>,
TOnChange extends undefined | FormValidateOrFn<TFormData>,
TOnChangeAsync extends undefined | FormAsyncValidateOrFn<TFormData>,
TOnBlur extends undefined | FormValidateOrFn<TFormData>,
TOnBlurAsync extends undefined | FormAsyncValidateOrFn<TFormData>,
TOnSubmit extends undefined | FormValidateOrFn<TFormData>,
TOnSubmitAsync extends undefined | FormAsyncValidateOrFn<TFormData>,
TOnServer extends undefined | FormAsyncValidateOrFn<TFormData>,
Even if the form desired by the user does not have any validations they are now forced to define their strictly typed form like so:
const myForm = new FormApi<MyInterface, undefined, undefined, undefined, undefined, undefined, undefined, undefined, undefined, undefined>
Which is extremely cumbersome. Furthermore, for our work project we also wrap a few Tanstack Form component with our custom Material UI components and we want those to be strictly typed, which would now become a complete flustercluck (excuse my french) with generic types.
I would really appreciate it if the defaults for the generic types could be re-introduced.
Your minimal, reproducible example
Steps to reproduce
- Go to the above linked TypeScript playground
- Go to the "errors" tab
- See the error "Expected 9 type arguments, but got 1."
Code used on playground:
import { useForm } from '@tanstack/react-form';
interface MyData {
name: string;
age: number;
}
const myForm = useForm<MyData>({
defaultValues: {
age: 30,
name: 'Favna'
}
})
Expected behavior
Expected behaviour is that the code above works just fine, regardless of the 8 missing generic types.
How often does this bug happen?
Every time
Screenshots or Videos
No response
Platform
- OS: MacOS
- Version: Seqouia 15.3.1
TanStack Form adapter
react-form
TanStack Form version
0.43.2
TypeScript version
5.7.3
Additional context
No response