© 2026 Hedgehog Software, LLC

TwitterGitHubDiscord
More
CommunitiesDocsAboutTermsPrivacy
Search
Star
Setup for Free
Drizzle TeamDT
Drizzle Team•2y ago•
7 replies
modii

drizzle-zod createInsertSchema gives optional types

I have the following table:

export const Recipe = pgTable("recipe", {
  id: uuid("id").notNull().primaryKey().defaultRandom(),
  title: varchar("title", { length: 256 }).notNull(),
  description: text("description").notNull(),
  mainImage: varchar("main_image", { length: 512 }),
  ingredientNames: varchar("ingredient_names", { length: 255 }).array().notNull(), // Array of ingredient names
  ingredientQuantities: real("ingredient_quantities").array().notNull(), // Array of ingredient quantities
  ingredientUnits: varchar("ingredient_units", { length: 20 }).array().notNull(), // Array of ingredient units
  stepDescriptions: text("step_descriptions").array().notNull(), // Array of step descriptions
  stepImages: varchar("step_images", { length: 512 }).array().notNull(), // Array of step images
  createdAt: timestamp("created_at").defaultNow().notNull(),
  updatedAt: timestamp("updated_at", {
    mode: "date",
    withTimezone: true,
  }).$onUpdateFn(() => sql`now()`),
  postedBy: uuid("posted_by").references(() => User.id, { onDelete: "cascade" }),
});
export const Recipe = pgTable("recipe", {
  id: uuid("id").notNull().primaryKey().defaultRandom(),
  title: varchar("title", { length: 256 }).notNull(),
  description: text("description").notNull(),
  mainImage: varchar("main_image", { length: 512 }),
  ingredientNames: varchar("ingredient_names", { length: 255 }).array().notNull(), // Array of ingredient names
  ingredientQuantities: real("ingredient_quantities").array().notNull(), // Array of ingredient quantities
  ingredientUnits: varchar("ingredient_units", { length: 20 }).array().notNull(), // Array of ingredient units
  stepDescriptions: text("step_descriptions").array().notNull(), // Array of step descriptions
  stepImages: varchar("step_images", { length: 512 }).array().notNull(), // Array of step images
  createdAt: timestamp("created_at").defaultNow().notNull(),
  updatedAt: timestamp("updated_at", {
    mode: "date",
    withTimezone: true,
  }).$onUpdateFn(() => sql`now()`),
  postedBy: uuid("posted_by").references(() => User.id, { onDelete: "cascade" }),
});


And I am using
drizzle-zod
drizzle-zod
to generate a Zod type from my schema:
export const CreateRecipeSchema = createInsertSchema(Recipe).omit({
  id: true,
  createdAt: true,
  updatedAt: true,
});
export const CreateRecipeSchema = createInsertSchema(Recipe).omit({
  id: true,
  createdAt: true,
  updatedAt: true,
});


However when I try to use the type within my
tRPC
tRPC
procedure as such, I get a typescript error, which seems to be complaining that the properties within
CreateRecipeSchema
CreateRecipeSchema
are optional:

  create: publicProcedure
  .input(CreateRecipeSchema)
  .mutation(async ({ input, ctx }) => {
    const newRecipe = await ctx.db.insert(Recipe).values(input);

    return newRecipe;
  }),
  create: publicProcedure
  .input(CreateRecipeSchema)
  .mutation(async ({ input, ctx }) => {
    const newRecipe = await ctx.db.insert(Recipe).values(input);

    return newRecipe;
  }),


I'm quite new to drizzle and zod, and from what I gather from documentation, I am using zod correctly, but I am not sure.
Drizzle TeamJoin
The official Discord for all Drizzle related projects, such as Drizzle ORM, Drizzle Kit, Drizzle Studio and more!
11,879Members
Resources
Was this page helpful?

Similar Threads

Recent Announcements

Similar Threads

Drizzle-zod createInsertSchema types
Drizzle TeamDTDrizzle Team / help
3y ago
Unexpected behaviour of drizzle-zod createInsertSchema
Drizzle TeamDTDrizzle Team / help
12mo ago
[postgres][zod] createInsertSchema
Drizzle TeamDTDrizzle Team / help
2y ago
Monorepo drizzle-zod types problem
Drizzle TeamDTDrizzle Team / help
9mo ago