Skip to content

[BUG]: PgInsertValue regression in 0.36.4 #3620

Open
@jansedlon

Description

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.36.4

What version of drizzle-kit are you using?

0.28.1

Other packages

typescript@5.7.2

Describe the Bug

Full example is in CodeSandbox. Examples are at the bottom.

Basically the signature of PgInsertValue must have changed in some way because when using Omit for example:

  1. It's not equal to $inferInsert
  2. It returns completely wrong types

Given this table

// This table has 40 columns
export const invoices = pgTable("Invoice", {
  id: text("id")
    .$defaultFn(() => createId())
    .primaryKey(),
  type: invoiceTypeEnum("type").notNull(),
  languageId: text("languageId"),
  invoiceNumber: text("invoiceNumber").notNull(),
  issueDate: timestamp("issueDate", { mode: "date", precision: 3 }).notNull(),
  transactionDate: timestamp("transactionDate", { mode: "date", precision: 3 }),
  paymentDate: timestamp("paymentDate", { mode: "date", precision: 3 }),
  dueDate: timestamp("dueDate", { mode: "date", precision: 3 }),
  serviceDate: timestamp("serviceDate", { mode: "date", precision: 3 }),
  supplierVat: text("supplierVat"),
  supplierName: text("supplierName").notNull(),
  supplierEmail: text("supplierEmail"),
  supplierAddressLine1: text("supplierAddressLine1"),
  supplierAddressLine2: text("supplierAddressLine2"),
  supplierCity: text("supplierCity"),
  supplierPostalCode: text("supplierPostalCode"),
  supplierCountry: text("supplierCountry"),
  supplierLocalIdentificationNumber: text("supplierLocalIdentificationNumber"),
  foreignCurrencyRate: doublePrecision("foreignCurrencyRate"),
  customerVat: text("customerVat"),
  customerName: text("customerName").notNull(),
  customerEmail: text("customerEmail"),
  customerAddressLine1: text("customerAddressLine1"),
  customerAddressLine2: text("customerAddressLine2"),
  customerCity: text("customerCity"),
  customerPostalCode: text("customerPostalCode"),
  customerCountry: text("customerCountry"),
  customerLocalIdentificationNumber: text("customerLocalIdentificationNumber"),
  userId: text("userId"),
  totalAmount: doublePrecision("totalAmount").notNull(),
  totalTaxAmount: doublePrecision("totalTaxAmount").notNull(),
  currencyCode: text("currencyCode").notNull(),
  taxRate: doublePrecision("taxRate").notNull(),
  taxableAmount: doublePrecision("taxableAmount").notNull(),
  taxAmount: doublePrecision("taxAmount").notNull(),
  publicLocation: text("publicLocation"),
  privateLocation: text("privateLocation"),
  viesCheckId: text("viesCheckId"),
  createdAt: timestamp("createdAt", { mode: "date", precision: 3 })
    .defaultNow()
    .notNull(),
  updatedAt: timestamp("updatedAt", { mode: "date", precision: 3 })
    .defaultNow()
    .$onUpdateFn(() => new Date())
    .notNull(),
});

And these types

// This type has correctly 40 properties
type InferInsert = typeof invoices.$inferInsert;

// This also has 40 properties
type InsertValue = PgInsertValue<typeof invoices>;

If I use omit like this

// This has correctly 39 properties
type InferInsert = Omit<typeof invoices.$inferInsert, 'id'>;

// This has 11? 😅
type InsertValue = Omit<PgInsertValue<typeof invoices>, 'id'>;

The same goes with using keyof, etc. The type completely changes.

Why am i reporting this? I have a function to create an invoice and the payload signature is like this

interface CreateInvoicePayload
  extends Omit<
    PgInsertValue<typeof invoices>,
    "id" | "type" | "invoiceNumber"
  > {
  tx: Parameters<Parameters<(typeof db)["transaction"]>[0]>[0];
  type: InvoiceType;
  lineItems: Omit<PgInsertValue<typeof invoiceLineItems>, "id" | "invoiceId">[];
  customFields: Omit<
    PgInsertValue<typeof invoiceCustomFields>,
    "id" | "invoiceId"
  >[];
}

Since i'm using Omit there, the typescript complains out of nowhere.

I have tried to downgrade typescript version, but the result is the same, it only happens when i update drizzle-orm from 0.36.3 to 0.36.4

Metadata

Assignees

Labels

bugSomething isn't workingpriorityWill be worked on nextqb/crud

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions