`$on` argument type error when extending prisma client
See original GitHub issueBug description
When extending the PrismaClient
class it is not possible to pass the query
event type to prisma.$on()
even though the correct options are passed to the PrismaClient
in the super()
call.
class Test extends PrismaClient {
constructor() {
super({
log: [
{
emit: "event",
level: "query",
},
],
});
this.$on("query", (e) => {
console.log(e);
});
}
}
The code above produces the following error:
TS2345: Argument of type '"query"' is not assignable to parameter of type '"beforeExit"'.
How to reproduce
- Download the quick-start project
- Paste in the above code snippet
- Run
yarn dev
- See error
Expected behavior
The query
parameter is valid.
Prisma information
Nothing relevant
Environment & setup
- OS: Ubuntu (WSL on Windows 11)
- Database: SQLite
- Node.js version: 16.14.0
Prisma Version
prisma : 3.7.0
@prisma/client : 3.7.0
Current platform : debian-openssl-1.1.x
Query Engine (Node-API) : libquery-engine 8746e055198f517658c08a0c426c7eec87f5a85f (at node_modules/@prisma/engines/libquery_engine-debian-openssl-1.1.x.so.node)
Migration Engine : migration-engine-cli 8746e055198f517658c08a0c426c7eec87f5a85f (at node_modules/@prisma/engines/migration-engine-debian-openssl-1.1.x)
Introspection Engine : introspection-core 8746e055198f517658c08a0c426c7eec87f5a85f (at node_modules/@prisma/engines/introspection-engine-debian-openssl-1.1.x)
Format Binary : prisma-fmt 8746e055198f517658c08a0c426c7eec87f5a85f (at node_modules/@prisma/engines/prisma-fmt-debian-openssl-1.1.x)
Default Engines Hash : 8746e055198f517658c08a0c426c7eec87f5a85f
Studio : 0.445.0
Also happens on
prisma : 3.9.2
@prisma/client : 3.9.2
Current platform : debian-openssl-1.1.x
Query Engine (Node-API) : libquery-engine bcc2ff906db47790ee902e7bbc76d7ffb1893009 (at ../../node_modules/@prisma/engines/libquery_engine-debian-openssl-1.1.x.so.node)
Migration Engine : migration-engine-cli bcc2ff906db47790ee902e7bbc76d7ffb1893009 (at ../../node_modules/@prisma/engines/migration-engine-debian-openssl-1.1.x)
Introspection Engine : introspection-core bcc2ff906db47790ee902e7bbc76d7ffb1893009 (at ../../node_modules/@prisma/engines/introspection-engine-debian-openssl-1.1.x)
Format Binary : prisma-fmt bcc2ff906db47790ee902e7bbc76d7ffb1893009 (at ../../node_modules/@prisma/engines/prisma-fmt-debian-openssl-1.1.x)
Default Engines Hash : bcc2ff906db47790ee902e7bbc76d7ffb1893009
Studio : 0.457.0
Issue Analytics
- State:
- Created 2 years ago
- Reactions:13
- Comments:15 (7 by maintainers)
Top Results From Across the Web
Prisma Client API (Reference)
API reference documentation for Prisma Client. ... 1export type LogLevel = 'info' | 'query' | 'warn' | 'error' ... This argument is optional....
Read more >Prisma/Typescript: how to extend client? - Stack Overflow
I implemented such class: import { PrismaClient } from '@prisma/client'; export type NotStartsWith< S, Prefix extends string, > = S extends ...
Read more >prisma is not assignable to type - You.com | The AI Search ...
Environment & setup · Bug description. A TS error is thrown when orderBy clause is defined as a variable and passed into findMany...
Read more >Prisma plugin for Pothos GraphQL
prismaField({ type: 'User', resolve: async (query, root, args, ctx, info) => prisma.user.findUniqueOrThrow({ // the `query` argument will add in `include`s or ` ...
Read more >Dynamic return type based on input parameter in TypeScript ...
Prisma does a good job of type safety After using TypeORM for many ... User } from "@prisma/client"; type PostGetPayload<S extends Prisma.
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
@r1si the problem is mostly likely in your definition of the
Global
type.I suppose you probably have a definition that looks like this in your code:
but you need to have something like this instead:
@smitssjors in that case, I think, you should be able to specify all events during compile time and then just subscribe to the ones you need in run time: