question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Argument of type '"query"' is not assignable to parameter of type '"beforeExit"'.

See original GitHub issue

Bug description

Following the documentation to setup custom logging here https://www.prisma.io/docs/concepts/components/prisma-client/working-with-prismaclient/logging

I used:

  prisma.$on('query', (e: Prisma.QueryEvent) => {
    console.log('Query: ' + e.query)
    console.log('Params: ' + e.params)
    console.log('Duration: ' + e.duration + 'ms')
  })

but this gives the following ts error:

Argument of type '"query"' is not assignable to parameter of type '"beforeExit"'.ts(2345)

How to reproduce

Setup logging as mentioned above as per the docs.

Expected behavior

No response

Prisma information

// Add your schema.prisma
// Add your code using Prisma Client

Environment & setup

  • OS: macOS
  • Database: SQLite
  • Node.js version: v18.4.0

Prisma Version

❯ npx prisma -v
Environment variables loaded from .env
prisma                  : 4.5.0
@prisma/client          : 4.5.0
Current platform        : darwin
Query Engine (Node-API) : libquery-engine 0362da9eebca54d94c8ef5edd3b2e90af99ba452 (at node_modules/@prisma/engines/libquery_engine-darwin.dylib.node)
Migration Engine        : migration-engine-cli 0362da9eebca54d94c8ef5edd3b2e90af99ba452 (at node_modules/@prisma/engines/migration-engine-darwin)
Introspection Engine    : introspection-core 0362da9eebca54d94c8ef5edd3b2e90af99ba452 (at node_modules/@prisma/engines/introspection-engine-darwin)
Format Binary           : prisma-fmt 0362da9eebca54d94c8ef5edd3b2e90af99ba452 (at node_modules/@prisma/engines/prisma-fmt-darwin)
Format Wasm             : @prisma/prisma-fmt-wasm 4.5.0-43.0362da9eebca54d94c8ef5edd3b2e90af99ba452
Default Engines Hash    : 0362da9eebca54d94c8ef5edd3b2e90af99ba452
Studio                  : 0.476.0

Issue Analytics

  • State:closed
  • Created a year ago
  • Comments:7 (2 by maintainers)

github_iconTop GitHub Comments

2reactions
herzog0commented, Nov 3, 2022

@marceloverdijk I’ve managed do fix this with the following:

import {Prisma, PrismaClient} from "@prisma/client";

declare global {
  // allow global `var` declarations
  // eslint-disable-next-line no-var
  var prisma: PrismaClient<Prisma.PrismaClientOptions, "query"> | undefined;
}

That’s because in the type declaration of the PrismaClient, the first type argument is actually the client options. The second one refer to the logging attributes.

// node_modules/.prisma/client/index.d.ts
......

export class PrismaClient<
  T extends Prisma.PrismaClientOptions = Prisma.PrismaClientOptions,
  U = 'log' extends keyof T ? T['log'] extends Array<Prisma.LogLevel | Prisma.LogDefinition> ? Prisma.GetEvents<T['log']> : never : never,
  GlobalReject extends Prisma.RejectOnNotFound | Prisma.RejectPerOperation | false | undefined = 'rejectOnNotFound' extends keyof T
    ? T['rejectOnNotFound']

.........
1reaction
marceloverdijkcommented, Nov 2, 2022

Hi @SevInf I just tried it on my project but unfortunately it does not help…

Changing the global declaration to:

declare global {
  var prisma: PrismaClient<'query'> | undefined
}

gives now: Type '"query"' has no properties in common with type 'PrismaClientOptions'.ts(2559)

image
Read more comments on GitHub >

github_iconTop Results From Across the Web

$on argument type error when extending prisma client #11986
The code above produces the following error: TS2345: Argument of type '"query"' is not assignable to parameter of type '"beforeExit"'.
Read more >
Logging with Prisma 2 and NestJS - Dependency Injection ...
Currently on my first NestJS project. I am using Prisma 2, and would like to log the queries to the console in debug...
Read more >
prisma is not assignable to type - You.com | The AI Search ...
A simple update query inside the transaction gives me an error: Argument of type '() => Promise<Integration>' is not assignable to parameter of...
Read more >
[Community help wanted!] TypeScript Feedback v0.33+
Do you find it helpful that the generated graphql types are not ... Argument of type '"query"' is not assignable to parameter of...
Read more >
Argument Type not assignable to Parameter Type Variables
I'm passing an object of arguments into the graphcool api and am getting this: Argument type {tag: string, from: string, to: [string], ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found