I am building a NestJS project using Prisma ORM.
I created a PrismaService where I initialize the Prisma client and apply a custom extension (softDeleteExtension).
After doing that, TypeScript autocomplete / IntelliSense stops working — I only get suggestions up to:
this.prisma.client
and no model names appear after that (e.g. .user, .restaurant, etc.).
Here is my Prisma service:
export class PrismaService implements OnModuleInit, OnModuleDestroy {
public readonly client;
constructor(private readonly configService: ConfigService) {
const dbUrl = this.configService.get('DATABASE_URL');
const adapter = new PrismaPg({
connectionString: dbUrl,
});
this.client = new PrismaClient({ adapter })
.$extends(softDeleteExtension);
}
async onModuleInit() {
await this.client.$connect();
}
async onModuleDestroy() {
await this.client.$disconnect();
}
}
And I inject it in a service like this:
export class RestaurantService {
constructor(private readonly prisma: PrismaService) {}
async create(dto: CreateRestaurantDto) {
await this.prisma.client.user.create({
data: dto,
});
}
}
It seems like the $extends() call causes the Prisma client type to become any.
Question
How can I define the client property so that TypeScript keeps the correct Prisma Client types and autocomplete still works after calling $extends()?
Thanks!