form icon indicating copy to clipboard operation
form copied to clipboard

Error types are invalid when using globalFormValidation syntax

Open V1OL3TF0X opened this issue 8 months ago • 0 comments

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

V1OL3TF0X avatar Apr 21 '25 15:04 V1OL3TF0X