TanStack / TanStack/form

Error types are invalid when using globalFormValidation syntax

Open
#1,437 3 comments 3 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

area: types scope: core type: bug v1
Dominant language
TypeScript
Stars
6.7k
Forks
682
Avg merge
5d 18h
Merged PRs (30d)
7

Description

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

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with the linked StackBlitz reproduction in App.tsx and inspect the types of state.errors and state.errorMap while toggling the fields property. Trace the isGlobalFormValidatonError check and error normalization behavior, then verify that the inferred value is string | undefined when fields is present and remains correct when it is absent.

Written by the indexing model from the issue text.

Assessment

Tech stack
react, typescript
Domain
frontend
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Active
Clarity
Mostly clear
Newbie friendliness
65/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.