chrishoermann / zod-prisma-types

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

[BUG] type error in generated InputJsonValueSchema #247

Open jason-curtis opened 2 months ago

jason-curtis commented 2 months ago

Describe the bug a type error in generated InputJsonValueSchema

Screenshots Running tsc:

db/generated/zod/index.ts:39:14 - error TS2322: Type 'ZodLazy<ZodUnion<[ZodString, ZodNumber, ZodBoolean, ZodObject<{ toJSON: ZodFunction<ZodTuple<[], null>, ZodAny>; }, "strip", ZodTypeAny, { ...; }, { ...; }>, ZodRecord<...>, ZodArray<...>]>>' is not assignable to type 'ZodType<InputJsonValue, ZodTypeDef, InputJsonValue>'.
  Types of property '_type' are incompatible.
    Type 'string | number | boolean | any[] | { toJSON?: (...args: unknown[]) => any; } | Record<string, any>' is not assignable to type 'InputJsonValue'.
      Type '{ toJSON?: (...args: unknown[]) => any; }' is not assignable to type 'InputJsonValue'.
        Type '{ toJSON?: (...args: unknown[]) => any; }' is not assignable to type '{ toJSON(): unknown; }'.
          Property 'toJSON' is optional in type '{ toJSON?: (...args: unknown[]) => any; }' but required in type '{ toJSON(): unknown; }'.

39 export const InputJsonValueSchema: z.ZodType<Prisma.InputJsonValue> = z.lazy(() =>
                ~~~~~~~~~~~~~~~~~~~~

Found 1 error in db/generated/zod/index.ts:3

Contents of the generated inputJsonValueSchema:

export const InputJsonValueSchema: z.ZodType<Prisma.InputJsonValue> = z.lazy(() =>
  z.union([
    z.string(),
    z.number(),
    z.boolean(),
    z.object({ toJSON: z.function(z.tuple([]), z.any()) }),
    z.record(z.lazy(() => z.union([InputJsonValueSchema, z.literal(null)]))),
    z.array(z.lazy(() => z.union([InputJsonValueSchema, z.literal(null)]))),
  ])
);

Package versions (please complete the following information):

Additional context Zod generator in schema.prisma file:

generator zod {
  provider                         = "zod-prisma-types"
  createOptionalDefaultValuesTypes = true
  useDefaultValidators             = false
  writeNullishInModelTypes         = true // Accept "undefined" in nullable fields
  useTypeAssertions                = true // silence typescript issues :p
}