Bug: ZenStack v2 loses type information in TypeScript types for delegated polymorphic models
维护者通常 1 天内回复
还没有人认领这个 Issue。
评估
- 难度
- 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
- 平均合并
- 2 天 7 小时
- 30 天内合并 PR
- 18
环境准备
这个项目没有提供开发容器、Dockerfile 或贡献指南,环境需要你自己搭建:先看它的 README,通用步骤见我们的新手贡献指南。
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 Issue 编号。
zenstackhq/zenstack 的其他 Issue
-
难度 2/5 1-3 小时 新手友好度 68/100
zenstackhq/zenstack#2873 ·
维护者通常 1 天内回复
-
`@default` on a field of a `@map`-ed enum emits the enum name as the column default可能重新可做 @jkugsiya 于 8 天前认领,目前没有进行中的 PR。 未关闭runtime
难度 2/5 1-3 小时 新手友好度 78/100
zenstackhq/zenstack#2868 · 1 条评论 ·
维护者通常 1 天内回复
-
难度 2/5 1-3 小时 新手友好度 72/100
zenstackhq/zenstack#2694 · 3 条评论 ·
维护者通常 1 天内回复
-
难度 1/5 1 小时以内 新手友好度 68/100
zenstackhq/zenstack#2659 · 2 条评论 ·
维护者通常 1 天内回复
-
难度 2/5 1-3 小时 新手友好度 65/100
zenstackhq/zenstack#2542 · 1 条评论 ·
维护者通常 1 天内回复
查看 zenstackhq/zenstack 的全部 Issue
相似的 Issue
-
难度 2/5 1-3 小时 新手友好度 74/100
paperclipai/paperclip#17151 ·
维护者通常 1 天内回复
-
needs-triage
难度 2/5 1-3 小时 新手友好度 83/100
AgoraIO-Extensions/agent-infra#3159 ·
维护者通常 1 天内回复
-
blocklist addition
难度 1/5 1 小时以内 新手友好度 66/100
MetaMask/eth-phishing-detect#304596 ·
维护者通常 1 天内回复
-
friction
难度 2/5 1-3 小时 新手友好度 70/100
kentcdodds/kody#4142 ·
-
[Bug] Statistics | Task statistics are always empty on MikroORM with MySQL or SQLite可能已有人在做 @NdekoCode 今天认领。 未关闭
难度 2/5 1-3 小时 新手友好度 76/100
ever-co/ever-gauzy#11214 ·
维护者通常 1 天内回复