Hacktoberfest 2026:维护者为十月标记出来的 issue,仍然开放、适合新手。 浏览 Hacktoberfest issue

[Feature Request] support subtyping of primitives

未关闭
#2,526 4 条评论 0 个 reaction 已指派 0 人 在 GitHub 查看

维护者通常 1 天内回复

还没有人认领这个 Issue。

评估

难度
5/5
预计耗时
一周以上
新手友好度
20/100
Issue 类型
功能
描述清晰度
基本清楚
活跃度
冷清
技术栈
typescript
领域
backend

调研方向

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.

由索引模型根据 Issue 内容生成。

描述

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?)?

主要语言
TypeScript
星标
2.9k
派生
157
平均合并
11 小时 42 分钟
30 天内合并 PR
20

环境准备

这个项目没有提供开发容器、Dockerfile 或贡献指南,环境需要你自己搭建:先看它的 README,通用步骤见我们的新手贡献指南。

从这里开始

  1. 先读完整个 Issue,再读项目的贡献指南。
  2. 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
  3. Fork 仓库,在一个分支上完成修改。
  4. 提交 Pull Request,并在描述里引用这个 Issue 编号。

zenstackhq/zenstack 的其他 Issue

查看 zenstackhq/zenstack 的全部 Issue

相似的 Issue

更多 TypeScript Issue

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。