Skip to content

bug: useForm and FormApi require 9 generic types instead of 1 starting 0.43.0 #1175

@favna

Description

@favna

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

https://www.typescriptlang.org/play/?#code/JYWwDg9gTgLgBAbzgVwM4FMBi0RwL5wBmUEuA5AAIwCGAdqjQMYDWA9FOtYzALSE5kA3AChhwWjHRRCXdHACyATwAi1GomFwtcWtRDoAXHAZRxAcxHa41M4Z3IQAIyki8oxhHrwQi7FFwAvCgYfiAAPEqqNAB8ABQImtoAJugyyAA2MABq1OnI6KhGCVZWNnYAzAAMADSJJTp6dmSY1ABuumR1+MJ4AJRAA

Steps to reproduce

  1. Go to the above linked TypeScript playground
  2. Go to the "errors" tab
  3. 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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions