chrishoermann / zod-prisma-types

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

Generated input type error #195

Closed DiMatteoL closed 8 months ago

DiMatteoL commented 8 months ago

The generated/zod/index.ts file prevents the build for my Next.js project. Here is the error:

Type error: Type 'ZodObject<{ brand: ZodString; model: ZodString; year: ZodNullable<ZodOptional<ZodNumber>>; licensePlate: ZodString; ... 47 more ...; branch: ZodLazy<...>; }, "strict", ZodTypeAny, { ...; }, { ...; }>' is not assignable to type 'ZodType<VehicleCreateInput, ZodTypeDef, VehicleCreateInput>'.
  Types of property '_type' are incompatible.
    Type '{ brand?: string; model?: string; year?: number; licensePlate?: string; vin?: string; providerCategory?: string; type?: "ELECTRIC" | "HYBRID"; status?: "AVAILABLE" | "BOOKED" | "PREPARATION" | "REQUIRES_CHARGING" | "AWAY" | "MAINTENANCE" | "RETURNING_TODAY"; ... 43 more ...; branch?: BranchCreateNestedOneWithoutVehi...' is not assignable to type 'VehicleCreateInput'.
      Property 'brand' is optional in type '{ brand?: string; model?: string; year?: number; licensePlate?: string; vin?: string; providerCategory?: string; type?: "ELECTRIC" | "HYBRID"; status?: "AVAILABLE" | "BOOKED" | "PREPARATION" | "REQUIRES_CHARGING" | "AWAY" | "MAINTENANCE" | "RETURNING_TODAY"; ... 43 more ...; branch?: BranchCreateNestedOneWithoutVehi...' but required in type 'VehicleCreateInput'.

Here are the current state of my versions: "@prisma/client": "^4.11.0", "prisma": "^4.11.0", "zod": "^3.21.4", "zod-prisma-types": "^2.7.13"

As a way to fix it I wondered if there was a to pick a specific model for which to generate specific inputs for, and ignore all the rests ?

chrishoermann commented 8 months ago

@DiMatteoL I think this Error is related to the known bug with zod versions greater than 3.21.1. please try this version for now until a solution is found for this problem.

Digital39999 commented 8 months ago

@DiMatteoL I think this Error is related to the known bug with zod versions greater than 3.21.1. please try this version for now until a solution is found for this problem.

I'm just generally curious, what changed in zod versions above 3.21.1?

chrishoermann commented 8 months ago

@Digital39999 I actually don't know what causes the bug but since some optimizations handling generics where made in zod 3.21.2 and generics are used in our generated schmeas it must have to do something with these changes. See zod release

Closing this since I assume that reverting back to 3.21.1 fixed the issue