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

Bug: ZenStack v2 loses type information in TypeScript types for delegated polymorphic models

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

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

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

評価

難易度
3/5
見積もり時間
1〜2日
初心者へのやさしさ
45/100
issue の種類
バグ
明瞭さ
明確に書かれている
活発さ
停滞
技術スタック
typescript
領域
tooling

調査の方向性

Reproduce with the three-model schema above and inspect the generated TypeScript types: the discriminator literal survives on the Base union but widens to string on Foo and Bar. The cause is in ZenStack's schema-to-TypeScript emitter for @@delegate models — trace where the discriminator field type is inferred for each concrete model and why the literal is dropped there but not in the base union. Done means Foo emits type: "Foo" and Bar type: "Bar", so the Extract<Base, ...> workaround is no longer needed; verify against the regenerated types and the existing delegate type tests.

索引モデルが issue の本文から書いたものです。

説明

Description and expected behavior
There is a mismatch between the TypeScript type generated for the base model and all of its delegated submodels.

Consider the following schema:

model Base {
  id String @id @default(cuid(2))
  type String
  @@delegate(type)
}

model Foo extends Base {
  foo Number
}

model Bar extends Base {
  bar String
}

The types generated are as follows:

type Base = {
  id: string
  type: "Foo"
  foo: number
} | {
  id: string
  type: "Bar"
  bar: string
}

type Foo = {
  id: string
  type: string // Expected: "Foo"
  foo: number
}

type Bar = {
  id: string
  type: string // Expected: "Bar"
  bar: string
}

The types of the submodels Foo and Bar lose their discriminator, while the Base union does not. As a workaround, I use the following pattern everywhere:

type Foo = Extract<Base, { type: "Foo" }>
type Bar = Extract<Base, { type: "Bar" }>

Environment (please complete the following information):

  • ZenStack version: 2.21.0
  • Prisma version: 6.18.0
  • Database type: PostgreSQL

Additional context

主要言語
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 を短くまとめたダイジェスト。