much 2 yearnM
Convex Community2y ago
7 replies
much 2 yearn

Use zod schemas for argument validation

I am using the zod helper library to use zod as validation but it I get an error when trying to use the zod schema from another file, but it works when writing the schema in the zMutation

export const createTemplate = zMutation({
  args: createTemplateSchema, //<-breaks
  // {
  //   authorId: zid("users"),
  //   title: z.string(),
  //   goal: z.union([
  //     z.literal("bodybuilding"),
  //     z.literal("powerlifting"),
  //     z.literal("powerbuilding"),
  //     z.literal("mobility"),
  //     z.literal("sport"),
  //     z.literal("general"),
  //   ]),
  //   format: z.union([z.literal("split"), z.literal("program")]),
  //   weekLength: z.number(),
  //   days: z.array(DaySchema),
  //   maxWeeks: z.number(),
  // }

error: Index signature for type 'string' is missing in type 'ZodObject. Is it possible to pass a defined schema or must all zod validation be done at that scope
Was this page helpful?