Interactive Transaction not allowed by typescript
See original GitHub issueBug description
The following (simple) usage of the interactive transaction (as documented here) produces a nasty typescript error that I can not seem to get around. (My actual transaction contains more logic but I was able to reproduce the error this way.)
const p: Paragraph = await prisma.$transaction(async (prisma) => {
return prisma.paragraph.create({ data: data });
});
Argument of type '(prisma: any) => Promise<any>' is not assignable to parameter of type 'PrismaPromise<any>[]'.
Type '(prisma: any) => Promise<any>' is missing the following properties from type 'PrismaPromise<any>[]': pop, push, concat, join, and 27 more.ts(2345)
It seems to expect the simpler $transaction
API:
const [posts, totalPosts] = await prisma.$transaction([
prisma.post.findMany({ where: { title: { contains: 'prisma' } } }),
prisma.post.count(),
])
How to reproduce
Schema:
datasource db {
provider = "postgresql"
url = env("DATABASE_URL")
}
generator client {
provider = "prisma-client-js"
previewFeatures = ["referentialActions"]
}
model Paragraph {
id String @id @default(uuid())
content String
}
Code:
const p: Paragraph = await prisma.$transaction(async (prisma) => {
return prisma.paragraph.create({ data: data });
});
Expected behavior
Expected to behave as the interactive transaction documentation describes.
Prisma information
See ‘how to reproduce’.
Environment & setup
- OS: MacOS
- Database: PostgreSQL
- Node.js version: v16.4.2
- Typescript version: 4.3.5
Prisma Version
prisma : 2.27.0
@prisma/client : 2.27.0
Current platform : darwin
Query Engine : query-engine cdba6ec525e0213cce26f8e4bb23cf556d1479bb (at node_modules/@prisma/engines/query-engine-darwin)
Migration Engine : migration-engine-cli cdba6ec525e0213cce26f8e4bb23cf556d1479bb (at node_modules/@prisma/engines/migration-engine-darwin)
Introspection Engine : introspection-core cdba6ec525e0213cce26f8e4bb23cf556d1479bb (at node_modules/@prisma/engines/introspection-engine-darwin)
Format Binary : prisma-fmt cdba6ec525e0213cce26f8e4bb23cf556d1479bb (at node_modules/@prisma/engines/prisma-fmt-darwin)
Default Engines Hash : cdba6ec525e0213cce26f8e4bb23cf556d1479bb
Studio : 0.410.0
Issue Analytics
- State:
- Created 2 years ago
- Reactions:1
- Comments:7 (2 by maintainers)
Top Results From Across the Web
Prisma transaction in nodejs and typescript not working
So I use transaction but I got following error -:. Argument of type '(tx: any) => Promise' is not assignable to parameter of...
Read more >Typing for transaction doesn't include async function argument
Bug description. But typescript doesn't recognize it. Argument of type '(prismaClient: any) => Promise<any>' is not assignable to parameter of ...
Read more >Transactions and batch queries (Reference) - Prisma
Interactive transactions : pass a function that can contain user code including Prisma Client queries, non-Prisma code and other control flow to be...
Read more >Cross Module Transaction with Prisma - DEV Community
Prisma and Interactive Transaction. There's no doubt that Prisma boosts your productivity when dealing with Databases in Node.js + TypeScript.
Read more >Transactions and batched writes | Firestore - Firebase - Google
Transaction functions should not directly modify application state. Transactions will fail when the client is offline. The following example shows how to ...
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
Good catch! Opened: https://github.com/prisma/docs/issues/2162
You don’t have it added to the
previewFeatures
in your schema which is why it’s not working: https://github.com/prisma/prisma/releases/tag/2.29.0It should work fine after running
prisma generate
.