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.

prisma.$transaction(async (prisma) => { ... }) not allowed by typescript definitions

See original GitHub issue

Bug description

The prisma.$transaction(PrimsaPromise[]) method is included in the typescript definition for the client, but prisma.$transaction((prisma: PrismaClient): Promise) is not.

How to reproduce

In any typescript project:

prisma.$transaction(async (prisma) => {})

Run tsc -d

Result:

app/models/organization.server.ts:70:30 - error TS2345: 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 28 more.

70   return prisma.$transaction(async (prisma) => {
                                ~~~~~~~~~~~~~~~~~~~

Expected behavior

It should include the prisma.$transaction: (prisma: PrismaClient): Promise type in the type definition file, since it exists in the code as well.

Prisma information

Prisma.prismaVersion = {
  client: "3.11.1",
  engine: "1a2506facaf1a4727b7c26850735e88ec779dee9"
}

Environment & setup

  • OS: Darwin moxy.lan 21.4.0 Darwin Kernel Version 21.4.0: Fri Mar 18 00:46:32 PDT 2022; root:xnu-8020.101.4~15/RELEASE_ARM64_T6000 arm64

  • Database: PostgreSQL

  • Node.js version: v16.14.2

Prisma Version

Environment variables loaded from .env
prisma                  : 3.11.1
@prisma/client          : 3.11.1
Current platform        : darwin-arm64
Query Engine (Node-API) : libquery-engine 1a2506facaf1a4727b7c26850735e88ec779dee9 (at node_modules/@prisma/engines/libquery_engine-darwin-arm64.dylib.node)
Migration Engine        : migration-engine-cli 1a2506facaf1a4727b7c26850735e88ec779dee9 (at node_modules/@prisma/engines/migration-engine-darwin-arm64)
Introspection Engine    : introspection-core 1a2506facaf1a4727b7c26850735e88ec779dee9 (at node_modules/@prisma/engines/introspection-engine-darwin-arm64)
Format Binary           : prisma-fmt 1a2506facaf1a4727b7c26850735e88ec779dee9 (at node_modules/@prisma/engines/prisma-fmt-darwin-arm64)
Default Engines Hash    : 1a2506facaf1a4727b7c26850735e88ec779dee9
Studio                  : 0.458.0

Issue Analytics

  • State:closed
  • Created a year ago
  • Comments:11 (3 by maintainers)

github_iconTop GitHub Comments

2reactions
isaacscommented, Apr 25, 2022

Ah, I see it is at https://www.prisma.io/docs/concepts/components/prisma-client/transactions#the-transaction-api, but buried a bit. I got as far as “there are two ways”, tried one, it didn’t work, so came here.

Could add a note on that second bullet like “This requires additional config to enable, see below.”

2reactions
garrensmithcommented, Apr 20, 2022

@Ustice @isaacs does adding previewFeatures = ["interactiveTransactions"] and then regenerate your Prima client with npx prisma generate fix your issue?

Read more comments on GitHub >

github_iconTop Results From Across the Web

Typing for transaction doesn't include async function argument
I expect typings to match all features offered by the library. Prisma information. datasource db { provider = "postgresql" ...
Read more >
Prisma transaction in nodejs and typescript not working
I got the same error, I fix that with added previewFeatures = ["interactiveTransactions"] and then regenerate my schema with npx prisma ...
Read more >
Transactions and batch queries (Reference) - Prisma
This page explains the transactions API of Prisma Client. ... Using a query in a transaction does not influence the order of operations...
Read more >
Transactions - Prisma
Explore techniques for handling transactions with Prisma Client. ... The $transaction API does not allow you to pass IDs between distinct operations.
Read more >
Operating against partial structures of your model types - Prisma
Problem: Using variations of the generated model type. Description. In some scenarios, you may need a variation of the generated User type.
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