createInsertSchema

Hi,

I have small issue with createInsertSchema function. Optional columns can have value or be undefined or null - and null type conflicts with HTMLInputElement attributes. I can't find a way to override the type to be value | undefined.

Do you have any suggestions on how to tackle this? Code below

export const recipes = createTable("recipe", {
  id: int("id", { mode: "number" }).primaryKey({ autoIncrement: true }),
  name: text("name", { length: 256 }).notNull(),
  description: text("description", { length: 256 }),
  image: text("image", { length: 256 }),
  cookingTime: int("cookingTime", { mode: "number" }),
  favorite: int("favorite", { mode: "boolean" }),
  createdBy: text("createdBy", { length: 255 })
    .notNull()
    .references(() => users.id),
  createdAt: int("created_at", { mode: "timestamp" })
    .default(sql`CURRENT_TIMESTAMP`)
    .notNull(),
  updatedAt: int("updatedAt", { mode: "timestamp" }),
});

export const NewRecipeSchema = createInsertSchema(recipes);
export type NewRecipe = z.infer<typeof NewRecipeSchema>;


NewRecipe type is

type NewRecipe = {
    name: string;
    createdBy: string;
    id?: number | undefined;
    description?: string | null | undefined;
    image?: string | null | undefined;
    cookingTime?: number | null | undefined;
    favorite?: boolean | ... 1 more ... | undefined;
    createdAt?: Date | undefined;
    updatedAt?: Date | ... 1 more ... | undefined;
}


Just for clarity, i want to change, for example, description to be string | undefined.
Was this page helpful?