Closed andenacitelli closed 1 year ago
Really have no clue why TypeScript is treating this as an error. The type that the Envelope
type wraps has those Omitted fields fine. It's saying that this:
export const TaskCreateManyLocationInputSchema: z.ZodType<Omit<Prisma.TaskCreateManyLocationInput, "number" | "userEmail">> = z.object({
id: z.string().optional(),
completed: z.boolean().optional(),
title: z.string().min(1),
size: z.lazy(() => TaskSizeSchema).optional(),
description: z.string(),
// omitted: number: z.number().int(),
start: z.coerce.date().optional().nullable(),
end: z.coerce.date().optional().nullable(),
url: z.string().optional().nullable(),
parentId: z.string().optional().nullable(),
dependenciesIds: z.union([ z.lazy(() => TaskCreatedependenciesIdsInputSchema),z.string().array() ]).optional(),
dependentsIds: z.union([ z.lazy(() => TaskCreatedependentsIdsInputSchema),z.string().array() ]).optional(),
epicId: z.string().optional().nullable(),
projectId: z.string().optional().nullable(),
ingestionEventId: z.string().optional().nullable(),
// omitted: userEmail: z.string(),
createdAt: z.coerce.date().optional(),
updatedAt: z.coerce.date().optional()
}).strict();
Doesn't work with this type:
export type TaskCreateManyLocationInput = {
id?: string
completed?: boolean
title: string
size?: TaskSize
description: string
number: number
start?: Date | string | null
end?: Date | string | null
url?: string | null
parentId?: string | null
dependenciesIds?: TaskCreatedependenciesIdsInput | Enumerable<string>
dependentsIds?: TaskCreatedependentsIdsInput | Enumerable<string>
epicId?: string | null
projectId?: string | null
ingestionEventId?: string | null
userEmail: string
createdAt?: Date | string
updatedAt?: Date | string
}
I have a suspicion that this is because of the pnpm
workspace I'm working in. Will update if/as I make progress.
@aacitelli just from reading the error message and the types I would say that this is because the prisma type expects the number
and userEmail
in the createMany
method regardless of them being omitted in the zod type. Prisma does not know that the fields are omitted in the zod type and expectst them because they are required
in the internal type.
did you add them manually in the data that is passed to the createMany
method like
// lets assume 'inputData' is the data parsed via zod schema
const data = inputData.map(item => ({
...item, // actual zod parsed data
number: 2, // value needs to be added manually because required in internal prisma type but omitted in zod type
userEmail: "mail@mail.com", // same as above
)}
const createData = await prisma.task.createMany({
data, // should now work without complaints
})
This is only a quick shot but I think this is your problem here.
@chrishoermann I don't think the issue was with the library or Prisma, just my ts config. Running tsc
on the output messed up for me, but the types work fine and don't report errors anywhere outside of the generated index file, so I'm fine with ignoring it.
I'm getting a type mismatch between the generated Prisma types and the generated Zod types. This is distinct from the issue Zod is currently having.
Steps:
npx prisma generate
tsc
zod
:3.21.1
zod-prisma-types
:2.5.4
Initially thought it was because of the type mismatch error in the most recent few
zod
versions, but no dice.Seems to be related to me using the Omit functionality. Seems like the Prisma type retains those fields, but the Zod types do not. Example:
/// @zod.custom.omit(["input"])
Schema:
Error:
Happy to follow up with more information if you need it!