Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Using Prisma.XyzFindManyArgs breaks findMany typing in v4.16.0+ #20093

Closed
Valerionn opened this issue Jul 6, 2023 · 5 comments · Fixed by #20180
Closed

Using Prisma.XyzFindManyArgs breaks findMany typing in v4.16.0+ #20093

Valerionn opened this issue Jul 6, 2023 · 5 comments · Fixed by #20180
Assignees
Labels
bug/1-unconfirmed Bug should have enough information for reproduction, but confirmation has not happened yet. kind/bug A reported bug. team/client Issue for team Client. tech/typescript Issue for tech TypeScript. topic: client types Types in Prisma Client topic: clientExtensions topic: findMany() topic: prisma-client
Milestone

Comments

@Valerionn
Copy link

Bug description

We sometimes generate find options dynamically and use the Prisma.UserFindManyArgs type for this, e.g. in a case like this:

    const userFindMany: Prisma.UserFindManyArgs = {};

    if(true) { // Some condition is met
      userFindMany.where = { email: 'mail@example.com' };
      userFindMany.take = 1;
    }

    const users = await prismaClient.user.findMany({
      ...userFindMany,
      include: {
        userRoles: true,
      },
    });

    console.log(users[0].email); // This works
    console.log(users[0].userRoles); // But this doesn't

Starting with Prisma v4.16.0, the code above throws a typing error: TS2339: Property 'userRoles' does not exist on type [...]. I think this is probably caused by the new typing because of client extensions - but in my opinion, the code above should still work.

As a workaround, it's possible to write a custom type for userFindManyArgs, e.g. const userFindMany: { where?: Prisma.UserWhereInput; take?: number } = {};, but that's only a workaround for a breaking change.

How to reproduce

Use the code above, check if users[0].userRoles throws a typescript error.

Expected behavior

Same behavior as before - adding an include should always include the relations in the result typing.

Prisma information

// Add your schema.prisma
model User {
  id        Int      @id @default(autoincrement())
  email     String   @unique
  userRoles               UserRole[]
}

model UserRole {
  id        Int      @id @default(autoincrement())
}
// Add your code using Prisma Client
const prismaClient = new PrismaClient();

Environment & setup

  • OS: Windows
  • Database: PostgreSQL
  • Node.js version: v16.17.1
  • Typescript version: v5.1.6

Prisma Version

prisma                  : 4.16.2
@prisma/client          : 4.16.2
Current platform        : windows
Query Engine (Node-API) : libquery-engine 4bc8b6e1b66cb932731fb1bdbbc550d1e010de81 (at node_modules\@prisma\engines\query_engine-windows.dll.node)
Migration Engine        : migration-engine-cli 4bc8b6e1b66cb932731fb1bdbbc550d1e010de81 (at node_modules\@prisma\engines\migration-engine-windows.exe)
Format Wasm             : @prisma/prisma-fmt-wasm 4.16.1-1.4bc8b6e1b66cb932731fb1bdbbc550d1e010de81
Default Engines Hash    : 4bc8b6e1b66cb932731fb1bdbbc550d1e010de81
Studio                  : 0.484.0
@Valerionn Valerionn added the kind/bug A reported bug. label Jul 6, 2023
@Valerionn
Copy link
Author

Valerionn commented Jul 6, 2023

Probably related/duplicated to #19962 (seems like I didn't go back far enough when checking if this issue already exists, sorry - but it's at least an additional reproduction example)

@Jolg42 Jolg42 added bug/1-unconfirmed Bug should have enough information for reproduction, but confirmation has not happened yet. topic: prisma-client topic: client types Types in Prisma Client tech/typescript Issue for tech TypeScript. team/client Issue for team Client. topic: findMany() labels Jul 6, 2023
@Jolg42
Copy link
Member

Jolg42 commented Jul 6, 2023

@Valerionn Are you using a client extension? If so, could you share it with us?

@Valerionn
Copy link
Author

I'm not using any client extensions (it was just a speculation that it might be related to the changed typings for client extensions in 4.16.0)

@millsp
Copy link
Member

millsp commented Jul 12, 2023

Hey, thanks for the report. We have worked on a fix and would appreciate if you could give it a try. If you have some time, install @prisma/client@5.1.0-integration-fix-client-types-mixed-input-types.1 and prisma@5.1.0-integration-fix-client-types-mixed-input-types.1 and let me know how it went. Thanks :)

@Valerionn
Copy link
Author

Looks good to me, there are now no more typing errors with this version, thanks for the quick fix!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug/1-unconfirmed Bug should have enough information for reproduction, but confirmation has not happened yet. kind/bug A reported bug. team/client Issue for team Client. tech/typescript Issue for tech TypeScript. topic: client types Types in Prisma Client topic: clientExtensions topic: findMany() topic: prisma-client
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants