Export extended Prisma client types
Greetings,
I'm trying to export an extended Prisma client types from a library package that is meant to be use through multiple NestJS applications.
This package contains:
- Prisma schema
-
postinstall script to generate the prisma client and build the src/client.ts file with the extended client source code.
Code:
4 Replies
You selected the bot's instantaneous insights. Let me compile your answer right away!
It’s expected that an extended client’s type is not PrismaClient, and you must infer/export the extended type yourself. The docs recommend wrapping client creation and exporting the return type:
(“Type of an extended client” guidance) (Type of an extended client).
Then in your NestJS app:
If you prefer a singleton-style factory in the library, the docs also show using ReturnType with a factory function, which preserves the extended type when exported across packages (e.g., in a Turborepo, they export an extended prisma instance and types from a database package) (Type of an extended client, Export client and types).
If your ExtendedPrismaClientOptions is resolving to any, ensure:
- You export the type alias derived from ConstructorParameters<typeof PrismaClient>[0] from the library entrypoint.
- Your consumer imports that alias (not re-deriving it).
- Type generation/build order runs before publishing/consuming (as in the Turborepo guide) ([Export client and types](<https://www.prisma.io/docs/guides/turborepo#24-export-the-prism
How to use Prisma ORM with Turborepo | Prisma Documentation
Learn step-by-step how to integrate Prisma ORM with Turborepo to build modular, scalable monorepo architectures efficiently.
a-client-and-types>)).
Note: Extensions return a new client; they don’t mutate the original, so types must flow from the factory/instance you export (Argument of type 'DynamicClientExtensionThis'…).
🤔 Alright, thanks for letting us know that there's still some help needed. A team member will reply to you shortly.
In the meantime, please let us know any additional info, questions, or which parts of the answer may need clarification.
Hi!
Could you please elaborate on the issue you are running into?
Would you just like to use generated PrismaClient types in your Nest application?