sqliteTable infer optional vs required fields

I am trying to create optional fields on my model but no matter what I do the drizzle is inferring all the properties as required. See the example below:

const example = sqliteTable("example", {
  id: text("id").primaryKey(),
  required: text("required").notNull(),
  optional: text("optional"),
});

type NewExample = typeof example.$inferInsert;
// resolves in:
// type NewExample = {
//   id: string;
//   required: string;
// }

type Example = typeof example.$inferSelect;
// resolves in:
// type Example = {
//   id: string;
//   required: string;
//   optional: string;
// }

// my expectation:
// type Example = {
//   id: string;
//   required: string;
//   optional?: string;
// }
//
// or
//
// type Example = {
//   id: string;
//   required: string;
//   optional: string | undefined;
// }


Is there any way to achieve expected behaviour with the drizzle orm?
Was this page helpful?