Skip to content
This repository was archived by the owner on Jan 14, 2021. It is now read-only.
This repository was archived by the owner on Jan 14, 2021. It is now read-only.

$transaction spread operator #894

@TheAschr

Description

@TheAschr

Bug description

The $transaction function type definitions do not support spread operator. Typescript complains that it is not able to map the Alert type onto the Comment type.

How to reproduce

const [comment, ...unsentMessages] = await prisma.$transaction([
  prisma.comment.create({
    data: {},
  }),
  ...alerts.map((alert) =>
    prisma.unsentMessage.create({
      data: {
        content: alert.content,
      },
    })
  ),
]);

await Promise.all(
  unsentMessages.map(async (unsentMessage) => {
    await sendMessage(unsentMessage);
    await prisma.unsentMessage.delete({
      where: { id: unsentMessage.id },
    });
  })
);

Expected behavior

The $transaction function should allow passing in spread operator for transactional inserts on a variable length of unrelated items.

Environment & setup

  • Node.js version: 14.10.0
  • Typescript version: 3.9.7
  • Prisma version: @prisma/[email protected]

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions