I’m currently developing on monorepo, implementing internal module which has additional features base on nestjs-prisma
project structure is as following
- apps
| |_serviceA
| |_node_modules
| |_myPrismaModule (install built version of internal)
| |_src
| |_generated
| |_client
| |_default.js (where my required type lies in)
|
|- internal
| |_myPrismaModule
Since I’m using Prisma, PrismaClient
& Prisma
type will defer across all service , cuz its type is defined by how developer designs the prisma schema.
The problem I’m facing is that I can’t reference the type properly after interna module build.. (actually I can’t guarantee whether this problem is reference problem or not..)
My implementation is the following code, previously it worked well but after changes it started not to reference well.
//previous
import {Prisma, PrismaClient} from "@prisma/client"
@Injectable()
export class PrismaService
extends PrismaClient<Prisma.PrismaClientOptions, 'query' | 'info' | 'warn' | 'error'>
implements OnModuleInit{...}
------
// current
async function getPrismaClientType() {
const {Prisma, PrismaClient} = await import(
"~~absolutePath~~/src/apps/serviceA/src/generated/client/default.js'"
);
return PrismaClient as PrismaClient<
Prisma.PrismaClientOptions,
'query' | 'info' | 'warn' | 'error'
>;
}
@Injectable()
export class PrismaService
extends (await getPrismaClientType())
implements OnModuleInit{...}
It throwed Cannot find namespace 'Prisma'
but I just to proceed I just comment @ts-ignore
in this case.
And In service workspace, whenever I try to access type like below, compiler just thinks type as “any”.. any advise in this??
prismaService.banner.findMany // banner is any