prisma / extension-read-replicas

Prisma Client Extension to add read replica support to your Prisma Client
Apache License 2.0
96 stars 6 forks source link

Typescript `Property '$primary' does not exist on type` error occurred #23

Open ChoSeoHwan opened 8 months ago

ChoSeoHwan commented 8 months ago

Reproduce

reproduce package : https://github.com/ChoSeoHwan/prisma-extension-read-replicas-bug-0

  1. git clone https://github.com/ChoSeoHwan/prisma-extension-read-replicas-bug-0.git
  2. yarn install
  3. yarn prisma:generate
  4. yarn build
  5. see tsc build error

Error

Property '$primary' does not exist on type 'DynamicClientExtensionThis<TypeMap<InternalArgs & { result: {}; model: {}; query: {}; client: {}; }>, TypeMapCb, { result: {}; model: {}; query: {}; client: {}; }>'.

image

Solutions

This occurs when moduleResolution in tsconfig is NodeNext. The project is an esm module (type:module in package.json), Accordingly, the .js extension must be added when importing.

When checking dist/index.d.ts built from the current @prisma/extension-read-replicas library, When importing, it is confirmed that there is no .js extension.

For compatibility with multiple projects, you must add the .js extension.

carlosneves0 commented 7 months ago

Hello, we're using this library within Typescript, and we found that when using prisma.$primary() as specified in this blog post, we encounter the following error mesage:

Property '$primary' does not exist on type 'PrismaClient<PrismaClientOptions, never, DefaultArgs> | DynamicClientExtensionThis<TypeMap<InternalArgs & { result: {}; model: {}; query: {}; client: { ...; }; }>, TypeMapCb, { ...; }>'.
  Property '$primary' does not exist on type 'PrismaClient<PrismaClientOptions, never, DefaultArgs>'.ts(2339)

By silencing the Typescript error with a // @ts-ignore comment, the client works as expected. Is our problem related? Is there anything we can do to solve this type issue?


Versions:

"@prisma/client": "^5.7.0",
"@prisma/extension-read-replicas": "^0.3.0",