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

Type error in a self-relation schema #85

Closed
lightbluepoppy opened this issue May 25, 2023 · 1 comment
Closed

Type error in a self-relation schema #85

lightbluepoppy opened this issue May 25, 2023 · 1 comment

Comments

@lightbluepoppy
Copy link

Bug description

There are multiple type errors in my generated schema file TaskCreateOrConnectWithoutSubtasksInput.schema.ts.

I think that this error occurs because this is a self-reference.

❯ npm run build

> [email protected] build
> next build
- info Linting and checking validity of types ..Failed to compile.

./prisma/generated/schemas/objects/TaskCreateOrConnectWithoutSubtasksInput.schema.ts:8:7
Type error: Type 'ZodObject<{ where: ZodLazy<ZodType<TaskWhereUniqueInput, ZodTypeDef, TaskWhereUniqueInput>>; create: ZodUnion<...>; }, "strict", ZodTypeAny, { ...; }, { ...; }>' is not assignable to type 'ZodType<TaskCreateOrConnectWithoutSubtasksInput, ZodTypeDef, TaskCreateOrConnectWithoutSubtasksInput>'.
  The types of '_type.create' are incompatible between these types.
    Type '(TaskCreateWithoutSubtasksInput | TaskUncheckedCreateWithoutSubtasksInput) & (TaskCreateWithoutSubtasksInput | TaskUncheckedCreateWithoutSubtasksInput | undefined)' is not assignable to type '(Without<TaskCreateWithoutSubtasksInput, TaskUncheckedCreateWithoutSubtasksInput> & TaskUncheckedCreateWithoutSubtasksInput) | (Without<...> & TaskCreateWithoutSubtasksInput)'.
      Type 'TaskCreateWithoutSubtasksInput & TaskUncheckedCreateWithoutSubtasksInput' is not assignable to type '(Without<TaskCreateWithoutSubtasksInput, TaskUncheckedCreateWithoutSubtasksInput> & TaskUncheckedCreateWithoutSubtasksInput) | (Without<...> & TaskCreateWithoutSubtasksInput)'.
        Type 'TaskCreateWithoutSubtasksInput & TaskUncheckedCreateWithoutSubtasksInput' is not assignable to type 'Without<TaskUncheckedCreateWithoutSubtasksInput, TaskCreateWithoutSubtasksInput> & TaskCreateWithoutSubtasksInput'.
          Type 'TaskCreateWithoutSubtasksInput & TaskUncheckedCreateWithoutSubtasksInput' is not assignable to type 'Without<TaskUncheckedCreateWithoutSubtasksInput, TaskCreateWithoutSubtasksInput>'.
            Types of property 'userId' are incompatible.
              Type 'string' is not assignable to type 'undefined'.

   6 | import type { Prisma } from '@prisma/client'
   7 | 
>  8 | const Schema: z.ZodType<Prisma.TaskCreateOrConnectWithoutSubtasksInput> =
     |       ^
   9 |   z
  10 |     .object({
  11 |       where: z.lazy(() => TaskWhereUniqueInputObjectSchema),

How to reproduce

I am not sure. I can help if someone give me any instruction.

Expected behavior

No response

Prisma information

model Task {
  id          String    @id @default(cuid())
  title       String
  user        User      @relation(fields: [userId], references: [id])
  userId      String
  createdAt   DateTime  @default(now())
  updatedAt   DateTime  @updatedAt
  startedAt   DateTime?
  endedAt     DateTime?
  superTaskId String?
  superTask   Task?     @relation(name: "Subtask", fields: [superTaskId], references: [id], onDelete: NoAction, onUpdate: NoAction)
  subtasks    Task[]    @relation(name: "Subtask")
  taskNum     Int?
  tags        Tag[]     @relation(name: "Tags")
  isArchived  Boolean   @default(false)

  @@index([userId])
  @@index([superTaskId])
}

Environment & setup

  • OS: macOS 13.2
  • Database: MySQL
  • Node.js version: v20.1.0

Prisma Version

@lightbluepoppy
Copy link
Author

#78 (comment)

Downgrading zod from 3.21.4 to 3.21.1 worked for me.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant