Issue
Hi I have following issue. I have prisma transaction but I would like to pass the prisma transaction client into a function like this:
...
prisma.$transaction(async (tx) => {
someFunction(tx)
})
...
function someFunction(tx: WHATTOTYPEHERE){
}
However I am doing it in typescript and I don't want to use type ANY. But i dont know how to type the interactive transactin prisma client... the "WHATTOTYPEHERE" type for it.
Any help is appreciated
Solution
If you peeked the definition of $transaction
, you would find this:
$transaction<R>(fn: (prisma: Omit<this, "$connect" | "$disconnect" | "$on" | "$transaction" | "$use">) => Promise<R>, options?: { maxWait?: number, timeout?: number }): Promise<R>
Copy/paste that definition and write your own type for use:
import { PrismaClient } from "@prisma/client";
type PrismaTransactionClient = Omit<PrismaClient, "$connect" | "$disconnect" | "$on" | "$transaction" | "$use">
function someFunction(tx: PrismaTransactionClient){
// code here
}
Answered By - kironto
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.