Why Partial<typeof x.$inferInsert> is required for Partial Updates

Is it necessary to always use Partial when performing a partial update on a table using db.update(...).set(...) or am I missing something? I'm using drizzle 0.42.0 For example, I've this schema
export const timestamps = {
createdAt: timestamp('created_at').notNull().defaultNow(),
updatedAt: timestamp('updated_at').notNull().defaultNow(),
};

export const modifiers = {
createdBy: varchar('created_by', { length: 64 }).notNull(),
updatedBy: varchar('updated_by', { length: 64 }).notNull(),
};

export const organizations = pgTable('organizations', {
organizationId: varchar('organization_id', { length: 64 }).primaryKey(),
name: varchar('name', { length: 255 }).notNull(),
deleted: boolean('deleted').notNull().default(false),
expired: boolean('expired').notNull().default(false),
expirationDate: timestamp('expiration_date').notNull(),
plan: varchar('plan', { length: 64 }).notNull(),
...modifiers,
...timestamps,
});
export const timestamps = {
createdAt: timestamp('created_at').notNull().defaultNow(),
updatedAt: timestamp('updated_at').notNull().defaultNow(),
};

export const modifiers = {
createdBy: varchar('created_by', { length: 64 }).notNull(),
updatedBy: varchar('updated_by', { length: 64 }).notNull(),
};

export const organizations = pgTable('organizations', {
organizationId: varchar('organization_id', { length: 64 }).primaryKey(),
name: varchar('name', { length: 255 }).notNull(),
deleted: boolean('deleted').notNull().default(false),
expired: boolean('expired').notNull().default(false),
expirationDate: timestamp('expiration_date').notNull(),
plan: varchar('plan', { length: 64 }).notNull(),
...modifiers,
...timestamps,
});
but following code gives me lint error (Object literal may only specify known properties, and 'x' does not exist in type)
await db.update(organizations)
.set({
name,
updatedBy: uid,
updatedAt: new Date(),
})
.where(eq(organizations.organizationId, organizationId));
await db.update(organizations)
.set({
name,
updatedBy: uid,
updatedAt: new Date(),
})
.where(eq(organizations.organizationId, organizationId));
I added type and lint error goes away
await db.update(organizations)
.set({
name,
updatedBy: uid,
updatedAt: new Date(),
} as Partial<typeof organizations.$inferInsert>)
.where(eq(organizations.organizationId, organizationId));
await db.update(organizations)
.set({
name,
updatedBy: uid,
updatedAt: new Date(),
} as Partial<typeof organizations.$inferInsert>)
.where(eq(organizations.organizationId, organizationId));
0 Replies
No replies yetBe the first to reply to this messageJoin

Did you find this page helpful?