omar-dulaimi / prisma-zod-generator

Prisma 2+ generator to emit Zod schemas from your Prisma schema
MIT License
535 stars 45 forks source link

Typescript errors in the generated router #78

Open atanaskanchev opened 1 year ago

atanaskanchev commented 1 year ago

Bug description

The generated router at generated/routers/Post.router.ts

 createOnePost: protectedProcedure
    .input(PostCreateOneSchema).mutation(async ({ ctx, input }) => {
      const createOnePost = await ctx.prisma.post.create(input);
      return createOnePost;
    }),

has the following error

Argument of type '{ data: (PostCreateInput | PostUncheckedCreateInput) & (PostCreateInput | PostUncheckedCreateInput | undefined); }' is not assignable to parameter of type '{ select?: PostSelect | null | undefined; include?: PostInclude | null | undefined; data: (Without<PostCreateInput, PostUncheckedCreateInput> & PostUncheckedCreateInput) | (Without<...> & PostCreateInput); }'.
  Types of property 'data' are incompatible.
    Type '(PostCreateInput | PostUncheckedCreateInput) & (PostCreateInput | PostUncheckedCreateInput | undefined)' is not assignable to type '(Without<PostCreateInput, PostUncheckedCreateInput> & PostUncheckedCreateInput) | (Without<...> & PostCreateInput)'.
      Type 'PostCreateInput & PostUncheckedCreateInput' is not assignable to type '(Without<PostCreateInput, PostUncheckedCreateInput> & PostUncheckedCreateInput) | (Without<...> & PostCreateInput)'.
        Type 'PostCreateInput & PostUncheckedCreateInput' is not assignable to type 'Without<PostUncheckedCreateInput, PostCreateInput> & PostCreateInput'.
          Type 'PostCreateInput & PostUncheckedCreateInput' is not assignable to type 'Without<PostUncheckedCreateInput, PostCreateInput>'.
            Types of property 'id' are incompatible.
              Type 'number | undefined' is not assignable to type 'undefined'.
                Type 'number' is not assignable to type 'undefined'.ts(2345)

How to reproduce

  1. Use the sample schema

Expected behavior

No response

Prisma information

generator client { provider = "prisma-client-js" }

generator trpc { provider = "prisma-trpc-generator" // output = "../../trpc/init/src/generated" output = "./generated" withMiddleware = "../../trpc/init/src/middleware" withShield = false contextPath = "../../trpc/init/src/context" trpcOptionsPath = "../../trpc/init/src/trpcOptions" }

datasource db { provider = "postgresql" url = env("DATABASE_URL") }

model User { id Int @id @default(autoincrement()) email String @unique name String? posts Post[] books Book[] }

model Post { id Int @id @default(autoincrement()) createdAt DateTime @default(now()) updatedAt DateTime @updatedAt title String content String? published Boolean @default(false) viewCount Int @default(0) author User? @relation(fields: [authorId], references: [id]) authorId Int? likes BigInt }

/// @@Gen.model(hide: true) model Book { id Int @unique title String author User? @relation(fields: [authorId], references: [id]) authorId Int? }

model Map { key String @id value String }

Environment & setup

Prisma Version

4.11.0
Frumba commented 1 year ago

I am having the same issue since today 🙏

ymc9 commented 1 year ago

Seems to be a zod issue: https://github.com/colinhacks/zod/issues/2184

Downgrading to zod 3.21.1 worked for me.

jamesrweb commented 1 year ago

Just hit this issue today also.

okeeffed commented 1 year ago

I also hit this issue. Subbing to notifications.

peterarusanoff commented 1 year ago

I am having the same issue Here

I am getting a whole list of errors

106 Errors

nonexisting prisma exports: AccountUncheckedUpdateManyWithoutAccountsInput'. Did you mean 'AccountUncheckedUpdateManyWithoutUserInput'?

type issues:

are the majority Type 'undefined' is not assignable to type 'string | AccountProviderProviderAccountIdCompoundUniqueInput'. Type 'number | number[] | undefined' is not assignable to type 'number[] | undefined'. Type 'number | number[] | null | undefined' is not assignable to type 'number[] | null | undefined'.

Prisma: "^5.3.0" zod: "3.21.1" @prisma/client: "5.3.0", DB: MongoDB

Please let me know of a work around