this code is also work and this is the 1st way
import { PrismaClient } from "@prisma/client";
export type PrismaTransactionalClient = Parameters<
Parameters<PrismaClient['$transaction']>[0]
>[0];
but there is a 2nd way and this is the official way
import { Prisma } from "@prisma/client";
export type PrismaTransactionalClient = Prisma.TransactionClient;
Answer from Vishal Kumar on Stack Overflowthis code is also work and this is the 1st way
import { PrismaClient } from "@prisma/client";
export type PrismaTransactionalClient = Parameters<
Parameters<PrismaClient['$transaction']>[0]
>[0];
but there is a 2nd way and this is the official way
import { Prisma } from "@prisma/client";
export type PrismaTransactionalClient = Prisma.TransactionClient;
The type in the (EDIT: formerly) accepted answer is no longer correct in the latest version of Prisma.
As a more future-proof type, you can use the Parameters type helper to extract the type from the $transaction method itself.
This will work even if the transaction type changes as long as the $transaction's method signature stays the same.
import { PrismaClient } from "@prisma/client";
export type PrismaTransactionalClient = Parameters<
Parameters<PrismaClient['$transaction']>[0]
>[0];
I got the same error, I fix that with added previewFeatures = ["interactiveTransactions"]
and then regenerate my schema with npx prisma generate
The previewFeatures = ["interactiveTransactions"] in your schema.prisma file. Should look like this:
generator client {
provider = "prisma-client-js"
previewFeatures = ["interactiveTransactions"]
}
Support extended Prisma Clients on `TransactionClient` type
typescript - How does Prisma handle transactions under the hood? - Stack Overflow
typescript - Using Prisma and transactions? - Stack Overflow
Expose the type that is passed to the interactive $transaction function
I’m writing v2 of an app I maintain and am considering moving from Sequelize to Primsa.
From my initial investigations I really like Primsa’s typescript support and the fact it returns plain JavaScript objects rather than complex model classes. However I’ve also encountered a few weirdnesses and quirks that have set my spidey-sense tingling and given me pause about adopting it.
In particular, the fact it generates custom client code to your node_modules seems very unusual (at least I’ve never seen this before) and ripe for causing unexpected, hard to debug problems - e.g. when caching dependencies on a build server.
It also seems strangely hard to have a createdBy column on database tables without an incredible amount of boilerplate setting up inverse relationships on your User model for every single other model in your schema.
And (I think a common complaint) not being able to split up your schema file is quite annoying.
I’ve only been toying with it for a couple of days and I’ve already run into these three wrinkles, which suggests to me that if I were to carry on, I might run into more. Is that the case? Are there other rough edges I should expect to encounter? It seems to make a lot of helpful things much easier, which is great. What does it make harder?
I’m also interested in hearing about any unexpected problems you ran into using Prisma in production - things it would be hard for me to figure out/predict from first principles and are only really learned through painful experience.
Asking here rather than on a Prisma sub in the hope of getting a wide range of responses. But I may ask there as well. Thanks!