-
Notifications
You must be signed in to change notification settings - Fork 9
Description
I'm getting TypeScript errors when using prisma-extension-redis in a NestJS project. The error says the inferred type "cannot be named without a reference to 'prisma-extension-redis/node_modules/@prisma/client/runtime/library'" and that "this is likely not portable."
Error message
The inferred type of 'withExtensions' cannot be named without a reference to 'prisma-extension-redis/node_modules/@prisma/client/runtime/library'. This is likely not portable. A type annotation is necessary.
When I create my own Prisma extension using Prisma.defineExtension(), it works perfectly fine with no TypeScript issues:
This works (another custom extension):
export const existsExtension = Prisma.defineExtension({
name: 'exists-extension',
model: {
$allModels: {
async exists<T>(this: T, where: Prisma.Args<T, 'findFirst'>['where']): Promise<boolean> {
const context = Prisma.getExtensionContext(this);
const count = await context['count']({
where,
take: 1
} as Prisma.Args<T, 'count'>);
return count > 0;
}
}
}
});
// No errors at all
const client = prisma.$extends(existsExtension);This breaks (prisma-extension-redis):
import { PrismaExtensionRedis } from "prisma-extension-redis";
const redisCacheExtension = PrismaExtensionRedis({
config: cacheConfig,
client: redisClient,
});
// TypeScript error about non-portable types
const client = prisma.$extends(redisCacheExtension);My Setup
- NestJS: 10.0.0
- @prisma/client: 6.5.0
- prisma: 6.5.0
- prisma-extension-redis: 2.1.1
- TypeScript: 5.5.4
What I think is happening
It looks like prisma-extension-redis isn't using Prisma.defineExtension() to create the extension properly. This causes TypeScript to infer really complex internal types that reference deep Prisma runtime paths, making them "non-portable."
This breaks type inference and causes alot of errors.
Could the extension be refactored to use Prisma.defineExtension() like other Prisma extensions? This would fix the type inference issues and make it work properly with TypeScript projects, especially in NestJS where proper typing is important.
Or am I missing another detail or a workaround?