Skip to content

[BUG]: Extending insert schemas makes nullable optional fields into required #4187

Open
@elieven

Description

@elieven

Report hasn't been filed before.

  • I have verified that the bug I'm about to report hasn't been filed before.

What version of drizzle-orm are you using?

0.39.3

What version of drizzle-kit are you using?

0.30.4

Other packages

[email protected]

Describe the Bug

const someTable = sqliteTable("some_table", {
  id: integer().primaryKey(),
  frequired: text().notNull(),
  foptional: text(),
})

const somethingInsertSchema = createInsertSchema(someTable, {
  foptional: schema => schema.email()
})

const someThing: z.infer<typeof somethingInsertSchema> = {
  frequired: "babajii"
}

In this example the type for someThing looks like this:

const someThing: {
    frequired: string;
    foptional: string | null;
    id?: number | undefined;
}

and there is a type error ts: Property 'foptional' is missing in type '{ frequired: string; }' but required in type '{ frequired: string; foptional: string | null; id?: number | undefined; }'.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions