Skip to content

Error types are invalid when using globalFormValidation syntax #1437

@V1OL3TF0X

Description

@V1OL3TF0X

Describe the bug

When returning an error from form validator in the form of { form: {}, fields: {} } it gets normalized, meaning the value in state.errorMap or state.errors is equal to error.form. This however is not reflected in type inference. Additionally, error is only normalized if it has fields field - returning { form: {} } is not normalized.

Your minimal, reproducible example

https://stackblitz.com/edit/vitejs-vite-dh4zqbne?file=src%2FApp.tsx

Steps to reproduce

  1. Open the example
  2. Input a value shorter than 10 characters into the input field
  3. hover over state.errors and state.errorMap types

Additonally, for weird mapping behaviour - switch the checkbox to disable the fields field in errors and see the value return t obeing an object.

Expected behavior

As a user, I'd expect the type to be correctly inferred and narrowed when the error passes isGlobalFormValidatonError check (in the example, the type should be string | undefined)

How often does this bug happen?

Every time

Screenshots or Videos

No response

Platform

  • OS: macos, Sequoia 15.41
  • Browser: Zen
  • browser version: 1.11.5b

TanStack Form adapter

react-form

TanStack Form version

v1.6.3

TypeScript version

v5.7.2

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