Error types are invalid when using globalFormValidation syntax
Nobody has claimed this yet.
- 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
- Open the example
- Input a value shorter than 10 characters into the input field
- hover over
state.errorsandstate.errorMaptypes
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
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- 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