Impossible to programmatically set "onServer" errors with setErrorMap due to conflicting type definitions
メンテナーはふだん 1 日以内に返信
まだ誰も着手していません。
評価
- 難易度
- 4/5
- 見積もり時間
- 3〜5日
- 初心者へのやさしさ
- 35/100
- issue の種類
- バグ
- 明瞭さ
- おおむね明確
- 活発さ
- 停滞
- 技術スタック
- react, typescript
調査の方向性
まず、issue で説明されている FormValidators、FormApi、BaseFormState の定義から始め、次に setErrorMap と useForm を使って、リンクされた StackBlitz の例で型エラーを再現します。onServer をプレースホルダーの validator や冗長な workaround なしに、型安全な方法で宣言およびプログラムから設定できれば、作業は完了です。
索引モデルが issue の本文から書いたものです。
説明
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!
- 主要言語
- TypeScript
- スター
- 6.8k
- フォーク
- 717
- 平均マージ
- 5日 22時間
- マージ済み PR(30日)
- 14
環境構築
- Dockerfile・Docker Compose ファイルなし
- プルリクエストのテンプレートあり
- コントリビューションガイドを読む
はじめの一歩
- issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
- 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
- リポジトリをフォークし、ブランチを切って変更します。
- issue 番号を参照したプルリクエストを送ります。
TanStack/form のほかの issue
-
難易度 1/5 1時間未満 初心者へのやさしさ 88/100
メンテナーはふだん 1 日以内に返信
-
Submit listener exceptions leave isSubmitting stuck true対応中かも @henricop が 14 日前に担当しました。 オープン
難易度 2/5 1〜3時間 初心者へのやさしさ 72/100
メンテナーはふだん 1 日以内に返信
-
handleSubmit calls onSubmit again while a submit is still pending (since 1.33.1)対応中かも @twotnguyen が 14 日前に担当しました。 オープン
難易度 2/5 1〜3時間 初心者へのやさしさ 78/100
メンテナーはふだん 1 日以内に返信
-
`isDefaultValue` is wrong when a field-level `defaultValue` is `null`対応中かも @fenet-as が 40 日前に担当しました。 オープン
難易度 2/5 1〜3時間 初心者へのやさしさ 76/100
TanStack/form#2427 · コメント 1 件 ·
メンテナーはふだん 1 日以内に返信
-
Async validator doesn't re-trigger `isValidating` after first failed validation対応中かも @drewsephski が 44 日前に担当しました。 オープン
難易度 2/5 1〜2日 初心者へのやさしさ 72/100
メンテナーはふだん 1 日以内に返信
似ている issue
-
clawsweeper:needs-maintainer-review clawsweeper:needs-product-decision clawsweeper:no-new-fix-pr clawsweeper:source-repro impact:ux-friction issue-rating: 🦞 diamond lobster P3
難易度 2/5 1〜3時間 初心者へのやさしさ 76/100
openclaw/openclaw#203385 · コメント 1 件 · リアクション 1 件 ·
メンテナーはふだん 1 日以内に返信
-
難易度 2/5 1〜3時間 初心者へのやさしさ 72/100
nwverse/persona#12800 · コメント 1 件 ·
メンテナーはふだん 1 日以内に返信
-
難易度 2/5 1〜3時間 初心者へのやさしさ 80/100
メンテナーはふだん 1 日以内に返信
-
[MCP]: page snapshots in .playwright-mcp/ are not git-ignored (.playwright-cli/ is, since #42318)オープン
難易度 2/5 1〜3時間 初心者へのやさしさ 62/100
microsoft/playwright#44289 ·
メンテナーはふだん 1 日以内に返信
-
good first issue
難易度 2/5 半日 初心者へのやさしさ 65/100
メンテナーはふだん 1 日以内に返信