Impossible to programmatically set "onServer" errors with setErrorMap due to conflicting type definitions
Mantenedores costumam responder em até 1 dia
Ninguém assumiu esta issue ainda.
Avaliação
- Dificuldade
- 4/5
- Tempo estimado
- 3-5 dias
- Facilidade para iniciantes
- 35/100
- Tipo de issue
- Bug
- Clareza
- Razoavelmente clara
- Status de atividade
- Estagnada
- Stack de tecnologia
- react, typescript
- Domínio
- developer-experience, frontend
Direção de pesquisa
Comece pelas definições de FormValidators, FormApi e BaseFormState descritas na issue e, em seguida, reproduza os erros de tipo no exemplo vinculado do StackBlitz usando setErrorMap e useForm. O trabalho estará concluído quando onServer puder ser declarado e definido programaticamente de forma type-safe, sem validadores placeholder ou workarounds verbosos.
Escrita pelo modelo de indexação a partir do texto da issue.
Descrição
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!
- Linguagem predominante
- TypeScript
- Estrelas
- 6.8k
- Forks
- 717
- Merge médio
- 5d 22h
- PRs com merge (30d)
- 14
Preparar o ambiente
- Sem Dockerfile nem arquivo Docker Compose
- Tem um modelo de pull request
- Ler o guia de contribuição
Primeiros passos
- Leia a issue inteira e depois o guia de contribuição do projeto.
- Comente na issue dizendo que vai assumir — evita que duas pessoas façam o mesmo trabalho.
- Faça um fork do repositório e trabalhe em uma branch.
- Abra um pull request que referencie o número da issue.
Mais de TanStack/form
-
Dificuldade 1/5 Menos de uma hora Facilidade para iniciantes 88/100
Mantenedores costumam responder em até 1 dia
-
Submit listener exceptions leave isSubmitting stuck trueTalvez já em andamento @henricop assumiu há 15 dias. Aberta
Dificuldade 2/5 1-3 horas Facilidade para iniciantes 72/100
Mantenedores costumam responder em até 1 dia
-
handleSubmit calls onSubmit again while a submit is still pending (since 1.33.1)Talvez já em andamento @twotnguyen assumiu há 14 dias. Aberta
Dificuldade 2/5 1-3 horas Facilidade para iniciantes 78/100
Mantenedores costumam responder em até 1 dia
-
`isDefaultValue` is wrong when a field-level `defaultValue` is `null`Talvez já em andamento @fenet-as assumiu há 40 dias. Aberta
Dificuldade 2/5 1-3 horas Facilidade para iniciantes 76/100
TanStack/form#2427 · 1 comentário ·
Mantenedores costumam responder em até 1 dia
-
Async validator doesn't re-trigger `isValidating` after first failed validationTalvez já em andamento @drewsephski assumiu há 44 dias. Aberta
Dificuldade 2/5 1-2 dias Facilidade para iniciantes 72/100
Mantenedores costumam responder em até 1 dia
Todas as issues de TanStack/form
Issues semelhantes
-
clawsweeper:needs-maintainer-review clawsweeper:needs-product-decision clawsweeper:no-new-fix-pr clawsweeper:source-repro impact:ux-friction issue-rating: 🦞 diamond lobster P3
Dificuldade 2/5 1-3 horas Facilidade para iniciantes 76/100
openclaw/openclaw#203385 · 1 comentário · 1 reação ·
Mantenedores costumam responder em até 1 dia
-
Dificuldade 2/5 1-3 horas Facilidade para iniciantes 72/100
nwverse/persona#12800 · 1 comentário ·
Mantenedores costumam responder em até 1 dia
-
Dificuldade 2/5 1-3 horas Facilidade para iniciantes 80/100
Mantenedores costumam responder em até 1 dia
-
[MCP]: page snapshots in .playwright-mcp/ are not git-ignored (.playwright-cli/ is, since #42318)Aberta
Dificuldade 2/5 1-3 horas Facilidade para iniciantes 62/100
microsoft/playwright#44289 ·
Mantenedores costumam responder em até 1 dia
-
good first issue
Dificuldade 2/5 Meio dia Facilidade para iniciantes 65/100
Mantenedores costumam responder em até 1 dia