`z.union` errors surface under `""` key instead of field-level errors

Đang mở
#2,081 0 bình luận 0 reaction 0 người được giao Xem trên GitHub

Maintainer thường phản hồi trong vòng 1 ngày

Chưa có ai nhận issue này.

Đánh giá

Độ khó
4/5
Thời gian dự kiến
3-5 ngày
Mức phù hợp với người mới
42/100
Loại issue
Lỗi
Độ rõ ràng
Khá rõ ràng
Mức độ hoạt động
Đình trệ
Công nghệ
typescript
Lĩnh vực
frontend

Hướng nghiên cứu

Bắt đầu với bản tái hiện tối thiểu trong src/index.tsx của StackBlitz, sau đó theo dõi cách lỗi invalid_union với một đường dẫn rỗng trở thành khóa "" trong fieldErrors. So sánh ánh xạ quan sát được với hành vi mong đợi ở cấp trường hoặc hành vi lỗi gốc, và thêm coverage cho trường hợp z.union đã tái hiện.

Do mô hình lập chỉ mục viết ra từ nội dung của issue.

Mô tả

v1 v2: needs investigation
Describe the bug

Body:

When using a Zod z.union as a form schema, validation failures produce an invalid_union error with path: [] (root). TanStack Form maps this to the "" (empty string) key in fieldErrors, making it impossible to associate the error with any specific field.

Repro:

const schema = z.union([
  z.object({ firstName: z.string().min(1), lastName: z.string().min(1) }),
  z.object({ email: z.string() }),
]);
// On failure: fieldErrors = { "": ["Invalid input"] }
Your minimal, reproducible example

https://stackblitz.com/edit/tanstack-form-zcs7lghv?file=src%2Findex.tsx&preset=node

Steps to reproduce

submit + inspect console.logs

Expected behavior

errors should surface on the relevant fields, or there should be a supported way to map root-level union errors to specific field paths.

How often does this bug happen?

None

Screenshots or Videos

No response

Platform

any

TanStack Form adapter

None

TanStack Form version

1.28.5

TypeScript version

No response

Additional context

No response

Ngôn ngữ chính
TypeScript
Star
6.8k
Fork
717
Merge trung bình
5 ngày 22 giờ
Pull request đã merge (30 ngày)
14

Chuẩn bị môi trường

Bắt đầu từ đâu

  1. Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
  2. Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
  3. Fork repository và làm thay đổi trên một nhánh.
  4. Mở pull request có tham chiếu số hiệu của issue.

Issue khác của TanStack/form

Tất cả issue của TanStack/form

Issue tương tự

Thêm issue về TypeScript

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.