Hacktoberfest 2026: le issue che i maintainer hanno segnato per ottobre, aperte e adatte ai principianti. Sfoglia le issue Hacktoberfest

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

Aperta
#2,334 0 commenti 0 reazioni 0 assegnatari Vedi su GitHub

I maintainer di solito rispondono entro 1 giorno

Nessuno ha ancora preso questa issue.

Valutazione

Difficoltà
3/5
Tempo stimato
1-2 giorni
Idoneità per principianti
45/100
Tipo di issue
Bug
Chiarezza
Specificata chiaramente
Stato di attività
Ferma
Stack tecnologico
typescript
Ambito
tooling

Direzione di ricerca

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.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Descrizione

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

Lingua principale
TypeScript
Stelle
2.9k
Fork
157
Merge medio
11h 42m
PR unite (30g)
20

Preparare l'ambiente

Questo progetto non fornisce container di sviluppo, Dockerfile né guida per i contributori, quindi l'ambiente è a tuo carico: parti dal suo README e consulta la nostra guida al primo contributo per i passaggi generali.

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Altre issue di zenstackhq/zenstack

Tutte le issue di zenstackhq/zenstack

Issue simili

Altre issue su TypeScript

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.