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.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
Fixed in v2, but still present as of
v1.33.5. The error type changed between the issue's reported version and latest, but the error is still wrong.