DT
Drizzle Team•6mo ago
Jack

db.insert(Table).values() gives TypeScript error "Object literal may only specify known properties"

Before I begin, let me clarify I am suuuper new to Drizzle! Loving it so far! Not sure if I should provide repro just yet (happy to later), but I am getting an issue where my table which currently is:
export const PostsTable = pgTable("posts", {
id,
...timestamps,
title: varchar("title", { length: 255 }).notNull(),
description: varchar("description", { length: 5_000 }).notNull(),
authorId: uuid("authorId")
.references(() => UsersTable.id)
.notNull()
});
export const PostsTable = pgTable("posts", {
id,
...timestamps,
title: varchar("title", { length: 255 }).notNull(),
description: varchar("description", { length: 5_000 }).notNull(),
authorId: uuid("authorId")
.references(() => UsersTable.id)
.notNull()
});
Is giving me this a long typescript error for the values method that basically boils down to this: Object literal may only specify known properties, and authorId does not exist in type ... When I run:
await db.insert(PostsTable).values({
authorId: req.user.userId,
description: formData.description,
fileId: dbFile!.fileId,
title: formData.title
});
await db.insert(PostsTable).values({
authorId: req.user.userId,
description: formData.description,
fileId: dbFile!.fileId,
title: formData.title
});
I feel like I am missing something basic, but I am scratching my head a bit! 😅 I have been able to successfully use the values method with no problems with very similar other tables. Thanks so much
1 Reply
Jack
JackOP•6mo ago
I fixed it... One second after asking. I accidentally had fileId in the insert, which trips it up. The error says authorId in addition to some other fields which confused me!
Want results from more Discord servers?
Add your server