zenstack icon indicating copy to clipboard operation
zenstack copied to clipboard

[Feature Request] Stronger Type Safety for Enhanced PrismaClient

Open jagodin opened this issue 6 months ago • 0 comments

Is your feature request related to a problem? Please describe. The types do not prevent me from passing a plain PrismaClient instance where an Enhanced<PrismaClient> is expected. For example, the following code type-checks, but at runtime, the client is not actually enhanced:

const db = new PrismaClient();
const enhanced = enhance(db, { user: {} });

async function doSomethingWithEnhanced(client: Enhanced<PrismaClient>) {
  // expects an enhanced client, but nothing prevents passing a plain PrismaClient
  await client.user.deleteMany();
}

// This compiles, but db is not actually enhanced!
await doSomethingWithEnhanced(db);

Describe the solution you'd like

I would like the type system to enforce that only an actually enhanced Prisma client can be passed where Enhanced<PrismaClient> is expected. Ideally, the Enhanced type should be branded or otherwise made incompatible with plain PrismaClient.

Describe alternatives you've considered

  • Wrapping the enhanced client in a custom class, but this adds boilerplate and loses some of the benefits of ZenStack's type system.

Additional context

n/a

jagodin avatar Jun 26 '25 16:06 jagodin