Hacktoberfest 2026:メンテナが10月に向けて印を付けた、オープンで初心者向けの issue。 Hacktoberfest の issue を見る

[Feature Request] support subtyping of primitives

オープン
#2,526 コメント 4 件 リアクション 0 件 担当者 0 名 GitHub で見る

メンテナーはふだん 1 日以内に返信

まだ誰も着手していません。

評価

難易度
5/5
見積もり時間
1週間以上
初心者へのやさしさ
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分
マージ済み PR(30日)
20

環境構築

このプロジェクトには開発コンテナ、Dockerfile、コントリビューションガイドがありません。まず README を読み、一般的な手順ははじめてのコントリビューションガイドを参照してください。

はじめの一歩

  1. issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
  2. 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
  3. リポジトリをフォークし、ブランチを切って変更します。
  4. issue 番号を参照したプルリクエストを送ります。

zenstackhq/zenstack のほかの issue

zenstackhq/zenstack の issue をすべて見る

似ている issue

TypeScript の issue をもっと見る

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。