Hacktoberfest 2026: the issues maintainers tagged for October, open and beginner-friendly. Browse Hacktoberfest issues

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

Open
#2,334 0 comments 0 reactions 0 assignees View on GitHub

Maintainers usually reply within 1 day

Nobody has claimed this yet.

Assessment

Difficulty
3/5
Estimated time
1-2 days
Newbie friendliness
45/100
Issue type
Bug
Clarity
Clearly specified
Activity status
Stale
Tech stack
typescript
Domain
tooling

Research direction

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.

Written by the indexing model from the issue text.

Description

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

Dominant language
TypeScript
Stars
2.9k
Forks
157
Avg merge
11h 42m
Merged PRs (30d)
20

Getting set up

This project ships no dev container, Dockerfile or contributing guide, so setting up is up to you: start from its README, and see our first-contribution guide for the general steps.

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from zenstackhq/zenstack

All issues in zenstackhq/zenstack

Similar issues

More TypeScript issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.