Impossible to programmatically set "onServer" errors with setErrorMap due to conflicting type definitions
Los mantenedores suelen responder en 1 día
Nadie ha tomado este issue todavía.
Evaluación
- Dificultad
- 4/5
- Tiempo estimado
- 3-5 días
- Aptitud para principiantes
- 35/100
- Tipo de issue
- Error
- Claridad
- Bastante claro
- Estado de actividad
- Estancado
- Stack tecnológico
- react, typescript
- Área
- developer-experience, frontend
Línea de trabajo
Comienza con las definiciones de FormValidators, FormApi y BaseFormState descritas en el issue y, a continuación, reproduce los errores de tipos en el ejemplo de StackBlitz enlazado usando setErrorMap y useForm. El trabajo estará terminado cuando onServer pueda declararse y establecerse mediante programación de forma segura respecto a los tipos, sin validadores de marcador de posición ni soluciones alternativas verbosas.
Escrito por el modelo de indexación a partir del texto del issue.
Descripción
Describe the bug
Currently, it's impossible to programmatically set a form-level server error using the semantically correct form.setErrorMap({ onServer: '...' }) in a type-safe way without resorting to complex workarounds.
The goal is to use the onServer key, which seems designed for server-side validation errors that are not part of the standard validation lifecycle.
The type of errorMap.onServer is derived from the TOnServer generic of the useForm hook.
This TOnServer generic is inferred from a validators.onServer property when initializing the form.
However, the FormValidators type definition does not include an onServer property. Attempting to add it results in a TypeScript error: Object literal may only specify known properties, and 'onServer' does not exist in type 'FormValidators<...>'.
Because onServer cannot be declared in validators, the TOnServer generic is inferred as undefined.
This leads to the final error when trying to use setErrorMap: Type 'string[]' is not assignable to type 'undefined'.
This design makes the onServer error channel effectively unusable in a type-safe manner out-of-the-box, creating a frustrating developer experience for the very common use case of handling server errors from a data-fetching library like TanStack Query.
Your minimal, reproducible example
https://stackblitz.com/edit/tanstack-form-cxredtu7?file=src%2Findex.tsx
Steps to reproduce
- Go to the provided link
Expected behavior
The onServer key in setErrorMap should be a first-class, dedicated channel for programmatic errors, completely decoupled from the validators system.
Its type in the errorMap should default to unknown or any, allowing developers to easily set server-side errors from external sources like useMutation without needing placeholder validators or verbose explicit generics. This would align with the pattern seen in other popular libraries like react-hook-form's setError('root.serverError', ...) and would greatly improve the developer experience for server-validated forms.
How often does this bug happen?
Every time
Screenshots or Videos
No response
Platform
OS: macOS
Browser: Chrome
Browser version: Version 138.0.7204.169 (Official Build) (arm64)
TanStack Form adapter
react-form
TanStack Form version
v1.15.0
TypeScript version
No response
Additional context
I dig a bit and seems like the core issue seems to be that TOnServer in FormApi is constrained as a validator type (extends undefined | FormAsyncValidateOrFn<TFormData>).
A potential fix could be to change the core type definitions to treat onServer as a special case, decoupling it from this constraint. For example, modifying the BaseFormState's errorMap definition to give onServer a static, flexible type.
Sorry if I'm missing something!
- Lenguaje dominante
- TypeScript
- Estrellas
- 6.8k
- Forks
- 717
- Merge medio
- 5 d 22 h
- PR fusionados (30 d)
- 14
Preparar el entorno
- Sin Dockerfile ni archivo de Docker Compose
- Tiene una plantilla de pull request
- Leer la guía de contribución
Primeros pasos
- Lee el issue completo y luego la guía de contribución del proyecto.
- Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
- Haz un fork del repositorio y trabaja en una rama.
- Abre un pull request que haga referencia al número del issue.
Más de TanStack/form
-
Dificultad 1/5 Menos de una hora Aptitud para principiantes 88/100
Los mantenedores suelen responder en 1 día
-
Submit listener exceptions leave isSubmitting stuck truePosiblemente ocupada @henricop la tomó hace 14 días. Abierto
Dificultad 2/5 1-3 horas Aptitud para principiantes 72/100
Los mantenedores suelen responder en 1 día
-
handleSubmit calls onSubmit again while a submit is still pending (since 1.33.1)Posiblemente ocupada @twotnguyen la tomó hace 14 días. Abierto
Dificultad 2/5 1-3 horas Aptitud para principiantes 78/100
Los mantenedores suelen responder en 1 día
-
`isDefaultValue` is wrong when a field-level `defaultValue` is `null`Posiblemente ocupada @fenet-as la tomó hace 40 días. Abierto
Dificultad 2/5 1-3 horas Aptitud para principiantes 76/100
TanStack/form#2427 · 1 comentario ·
Los mantenedores suelen responder en 1 día
-
Async validator doesn't re-trigger `isValidating` after first failed validationPosiblemente ocupada @drewsephski la tomó hace 44 días. Abierto
Dificultad 2/5 1-2 días Aptitud para principiantes 72/100
Los mantenedores suelen responder en 1 día
Todos los issues de TanStack/form
Issues similares
-
clawsweeper:needs-maintainer-review clawsweeper:needs-product-decision clawsweeper:no-new-fix-pr clawsweeper:source-repro impact:ux-friction issue-rating: 🦞 diamond lobster P3
Dificultad 2/5 1-3 horas Aptitud para principiantes 76/100
openclaw/openclaw#203385 · 1 comentario · 1 reacción ·
Los mantenedores suelen responder en 1 día
-
Dificultad 2/5 1-3 horas Aptitud para principiantes 72/100
nwverse/persona#12800 · 1 comentario ·
Los mantenedores suelen responder en 1 día
-
Dificultad 2/5 1-3 horas Aptitud para principiantes 80/100
Los mantenedores suelen responder en 1 día
-
[MCP]: page snapshots in .playwright-mcp/ are not git-ignored (.playwright-cli/ is, since #42318)Abierto
Dificultad 2/5 1-3 horas Aptitud para principiantes 62/100
microsoft/playwright#44289 ·
Los mantenedores suelen responder en 1 día
-
good first issue
Dificultad 2/5 Medio día Aptitud para principiantes 65/100
Los mantenedores suelen responder en 1 día