Hacktoberfest 2026: những issue maintainer đã đánh dấu cho tháng Mười, đang mở và phù hợp người mới. Xem issue Hacktoberfest

[Feature Request] support subtyping of primitives

Đang mở
#2,526 4 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ó
5/5
Thời gian dự kiến
Hơn một tuần
Mức phù hợp với người mới
20/100
Loại issue
Tính năng
Độ rõ ràng
Khá rõ ràng
Mức độ hoạt động
Ít trao đổi
Công nghệ
typescript
Lĩnh vực
backend

Hướng nghiên cứu

Design-level request: decide how primitive subtypes are declared and how validation attributes reach array elements, then carry that through ZModel parsing, validation and generated TypeScript types. Begin with how type declarations and @length-style attributes are parsed today and how scalar arrays are typed, and resolve the open question about nullable elements (PostTag?[]). Done means type PostTag { value String @length(1, 5) } used as PostTag[] validates each element, with tests covering arrays and nullability.

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

Mô tả

Is your feature request related to a problem? Please describe.
A clear and concise description of what the problem is. Ex. I'm always frustrated when [...]

Currently, it is not possible to validate elements of scalar arrays:

model Post {
  tags String[] @length(1, 5) // what if I wanted a tag itself to be between 1 and 5 characters?
}

Describe the solution you'd like
A clear and concise description of what you want to happen.

Allow subtyping of primitives so that validation attributes can be applied to them, then referenced as the element type of an array.

type PostTag {
  value String @length(1, 5)
}

model Post {
  value PostTag[]
}

The above method wouldn't require changes to the schema language grammar. However, I will still note that the following syntax could be more intuitive to some because it doesn't use the implicit value property like the above, and is more like a type alias.

type PostTag = String @length(1, 5)

Describe alternatives you've considered
A clear and concise description of any alternative solutions or features you've considered.

Validate in application code. But then there is some validation occurring as part of the schema definition and some happening elsewhere. It would be nice to centralize it.

Additional context
Add any other context or screenshots about the feature request here.

Open questions:

  1. Nullable array elements

    These (String?[]) are not currently allowed. Would these subtypes be forced as non-nullable, and required to be marked as nullable at the usage site (PostTag?)?

Ngôn ngữ chính
TypeScript
Star
2.9k
Fork
157
Merge trung bình
11 giờ 42 phút
Pull request đã merge (30 ngày)
20

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

Dự án này không cung cấp dev container, Dockerfile hay hướng dẫn đóng góp, nên bạn cần tự thiết lập môi trường: hãy bắt đầu từ README và xem hướng dẫn đóng góp lần đầu của chúng tôi để biết các bước chung.

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 zenstackhq/zenstack

Tất cả issue của zenstackhq/zenstack

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.