Skip to content

[BUG] Types generated when using @default(auth().id) are not compatible with third party libraryes #1440

@nahtnam

Description

@nahtnam

Description and expected behavior

https://github.com/nahtnam/zenstack-default-auth-bug

To reproduce, clone this repo and run:

npm install
npx zenstack generate
npx tsc --noEmit

To prove this is related to @default, you can remove it from this line: https://github.com/nahtnam/zenstack-default-auth-bug/blob/main/schema.zmodel#L38

Then regenerate zenstack and check the types

Also to prove that this is not a bug with the repo, you can change this line to directly use the prisma client and typescript will not complain: https://github.com/nahtnam/zenstack-default-auth-bug/blob/main/src/app/admin/%5B%5B...nextadmin%5D%5D/page.tsx#L20

Screenshots

Type 'import("/zenstack-default-auth-bug/node_modules/.zenstack/.logical-prisma-client/index-fixed").PrismaClient<import("/zenstack-default-auth-bug/node_modules/.zenstack/.logical-prisma-client/index-fixed").Prisma.PrismaClientOptions, never, import("/zen...' is not assignable to type 'import("/zenstack-default-auth-bug/node_modules/.prisma/client/index").PrismaClient<import("/zenstack-default-auth-bug/node_modules/.prisma/client/index").Prisma.PrismaClientOptions, never, import("/zenstack-default-auth-bug/node_module...'.
  Types of property '$transaction' are incompatible.
    Type '{ <P extends import("/zenstack-default-auth-bug/node_modules/.zenstack/.logical-prisma-client/index-fixed").Prisma.PrismaPromise<any>[]>(arg: [...P], options?: { ...; } | undefined): Promise<...>; <R>(fn: (prisma: Omit<...>) => Promise<...>, options?: { ...; } | undefined): Promise<...>; }' is not assignable to type '{ <P extends import("/zenstack-default-auth-bug/node_modules/.prisma/client/index").Prisma.PrismaPromise<any>[]>(arg: [...P], options?: { isolationLevel?: import("/zenstack-default-auth-bug/node_modules/.prisma/client/index").Prisma.TransactionIsolationLevel | un...'.
      Types of parameters 'arg' and 'fn' are incompatible.
        Type '(prisma: Omit<PrismaClient<PrismaClientOptions, never, DefaultArgs>, "$connect" | "$disconnect" | "$on" | "$transaction" | "$use" | "$extends">) => Promise<...>' is not assignable to type 'any[]'.

20     prisma: db,
       ~~~~~~

  node_modules/@premieroctet/next-admin/dist/utils/props.d.ts:11:5
    11     prisma: PrismaClient;
           ~~~~~~
    The expected type comes from property 'prisma' which is declared here on type 'Omit<GetPropsFromParamsParams, "isAppDir">'


Found 1 error in src/app/admin/[[...nextadmin]]/page.tsx:20

Environment (please complete the following information):

  • ZenStack version: [e.g., 2.0.0] 2.0.3
  • Prisma version: [e.g., 5.7.0] 5.13.0
  • Database type: [e.g. Postgresql] any/postgres

Additional context
N/A

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions