chrishoermann / zod-prisma-types

Generator creates zod types for your prisma models with advanced validation
Other
579 stars 43 forks source link

TS2322 error in ModelACreateOrConnectWithoutModelBInputSchema #183

Closed empz closed 10 months ago

empz commented 10 months ago

AppointmentCreateOrConnectWithoutCustomerInputSchema.ts (generated)

import type { Prisma } from "@prisma/client";
import { z } from "zod";
import { AppointmentCreateWithoutCustomerInputSchema } from "./AppointmentCreateWithoutCustomerInputSchema";
import { AppointmentUncheckedCreateWithoutCustomerInputSchema } from "./AppointmentUncheckedCreateWithoutCustomerInputSchema";
import { AppointmentWhereUniqueInputSchema } from "./AppointmentWhereUniqueInputSchema";

export const AppointmentCreateOrConnectWithoutCustomerInputSchema: z.ZodType<Prisma.AppointmentCreateOrConnectWithoutCustomerInput> =
  z
    .object({
      where: z.lazy(() => AppointmentWhereUniqueInputSchema),
      create: z.union([
        z.lazy(() => AppointmentCreateWithoutCustomerInputSchema),
        z.lazy(() => AppointmentUncheckedCreateWithoutCustomerInputSchema),
      ]),
    })
    .strict();

export default AppointmentCreateOrConnectWithoutCustomerInputSchema;

Error

Type 'ZodObject<{ where: ZodLazy<ZodType<AppointmentWhereUniqueInput, ZodTypeDef, AppointmentWhereUniqueInput>>; create: ZodUnion<...>; }, "strict", ZodTypeAny, { ...; }, { ...; }>' is not assignable to type 'ZodType<AppointmentCreateOrConnectWithoutCustomerInput, ZodTypeDef, AppointmentCreateOrConnectWithoutCustomerInput>'.
  The types of '_type.create' are incompatible between these types.
    Type '(AppointmentCreateWithoutCustomerInput | AppointmentUncheckedCreateWithoutCustomerInput) & (AppointmentCreateWithoutCustomerInput | ... 1 more ... | undefined)' is not assignable to type '(Without<AppointmentCreateWithoutCustomerInput, AppointmentUncheckedCreateWithoutCustomerInput> & AppointmentUncheckedCreateWithoutCustomerInput) | (Without<...> & AppointmentCreateWithoutCustomerInput)'.
      Type 'AppointmentCreateWithoutCustomerInput & AppointmentUncheckedCreateWithoutCustomerInput' is not assignable to type '(Without<AppointmentCreateWithoutCustomerInput, AppointmentUncheckedCreateWithoutCustomerInput> & AppointmentUncheckedCreateWithoutCustomerInput) | (Without<...> & AppointmentCreateWithoutCustomerInput)'.
        Type 'AppointmentCreateWithoutCustomerInput & AppointmentUncheckedCreateWithoutCustomerInput' is not assignable to type 'Without<AppointmentUncheckedCreateWithoutCustomerInput, AppointmentCreateWithoutCustomerInput> & AppointmentCreateWithoutCustomerInput'.
          Type 'AppointmentCreateWithoutCustomerInput & AppointmentUncheckedCreateWithoutCustomerInput' is not assignable to type 'Without<AppointmentUncheckedCreateWithoutCustomerInput, AppointmentCreateWithoutCustomerInput>'.
            Types of property 'id' are incompatible.
              Type 'number | undefined' is not assignable to type 'undefined'.
                Type 'number' is not assignable to type 'undefined'.

schema.prisma (simplified)

model Customer {
    id           Int           @id @default(autoincrement())
    fullName     String
    email        String?
    createdAt    DateTime      @default(now())
    updatedAt    DateTime      @updatedAt
    appointments Appointment[]
}

model Appointment {
    id                Int               @id @default(autoincrement())
    start             DateTime
    end               DateTime
    createdAt         DateTime          @default(now())
    updatedAt         DateTime          @updatedAt
    customer          Customer          @relation(fields: [customerId], references: [id], onDelete: Cascade)
    customerId        Int
}
chrishoermann commented 10 months ago

@empz sadly there is still an unresolved issue with zod versions greater than 3.21.1 - see here. So please use zod 3.21.1 for now.