zod-prisma-types
zod-prisma-types copied to clipboard
[BUG] type error in generated InputJsonValueSchema
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):
- zod:
> yarn why zod -R
└─ root-workspace-0b6124@workspace:.
├─ zod-prisma-types@npm:3.1.6 (via npm:^3.1.6)
│ └─ zod@npm:3.23.5 (via npm:^3.22.4)
└─ zod@npm:3.21.1 (via npm:3.21.1)
- prisma:
> yarn why prisma
└─ @redwoodjs/cli@npm:7.0.6
└─ prisma@npm:5.9.1 (via npm:5.9.1)
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
}
I am facing this issue, are there any fixes yet?
Me too~~~
Same here.
My temporary work around is transforming
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)]))),
])
);
into
export const InputJsonValueSchema: z.ZodType<Prisma.InputJsonValue> = z.lazy(() =>
z.union([
z.string(),
z.number(),
z.boolean(),
z.record(z.lazy(() => InputJsonValueSchema)),
z.array(z.lazy(() => InputJsonValueSchema)),
])
);
It would be nice to have a fix though 🙏🏻. @chrishoermann I just discovered this library and am really loving having it—thanks for your work!
You must use the strict mode or enable strictNullChecks in your tsconfig.json. It's worked to me.