drizzle-team / drizzle-team/drizzle-orm
[BUG]: PgInsertValue regression in 0.36.4
- Dominant language
- TypeScript
- Stars
- 35.8k
- Forks
- 1.6k
- Avg merge
- 2d 7h
- Merged PRs (30d)
- 4
Description
### Report hasn't been filed before.
- [X] 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](https://codesandbox.io/p/sandbox/6tn92t). 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
```ts
// 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
```ts
// This type has correctly 40 properties
type InferInsert = typeof invoices.$inferInsert;
// This also has 40 properties
type InsertValue = PgInsertValue;
```
If I use omit like this
```ts
// This has correctly 39 properties
type InferInsert = Omit;
// This has 11? 😅
type InsertValue = Omit, '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
```ts
interface CreateInvoicePayload
extends Omit<
PgInsertValue,
"id" | "type" | "invoiceNumber"
> {
tx: Parameters[0]>[0];
type: InvoiceType;
lineItems: Omit, "id" | "invoiceId">[];
customFields: Omit<
PgInsertValue,
"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`
Contributor guide
Assessment
This issue has not been assessed yet.