chimelli
DTDrizzle Team
•Created by chimelli on 4/22/2024 in #help
Id being required in types when using insert and values
Hello! I' been following the tutorial and I'm having a issue with the following function:
I'm getting the following error:
and this is my schema:
What could be happening?
export const addTodo = async (text: string) => {
await db.insert(todo).values({
text: text,
done: false,
});
revalidatePath("/");
};
export const addTodo = async (text: string) => {
await db.insert(todo).values({
text: text,
done: false,
});
revalidatePath("/");
};
No overload matches this call.
Overload 1 of 2, '(value: { id: number | SQL<unknown> | Placeholder<string, any>; text: string | SQL<unknown> | Placeholder<string, any>; done?: boolean | SQL<unknown> | Placeholder<string, any> | undefined; }): PgInsertBase<...>', gave the following error.
Argument of type '{ text: string; done: false; }' is not assignable to parameter of type '{ id: number | SQL<unknown> | Placeholder<string, any>; text: string | SQL<unknown> | Placeholder<string, any>; done?: boolean | SQL<unknown> | Placeholder<string, any> | undefined; }'.
Property 'id' is missing in type '{ text: string; done: false; }' but required in type '{ id: number | SQL<unknown> | Placeholder<string, any>; text: string | SQL<unknown> | Placeholder<string, any>; done?: boolean | SQL<unknown> | Placeholder<string, any> | undefined; }'.
Overload 2 of 2, '(values: { id: number | SQL<unknown> | Placeholder<string, any>; text: string | SQL<unknown> | Placeholder<string, any>; done?: boolean | SQL<unknown> | Placeholder<string, any> | undefined; }[]): PgInsertBase<...>', gave the following error.
Object literal may only specify known properties, and 'text' does not exist in type '{ id: number | SQL<unknown> | Placeholder<string, any>; text: string | SQL<unknown> | Placeholder<string, any>; done?: boolean | SQL<unknown> | Placeholder<string, any> | undefined; }[]'.ts(2769)
No overload matches this call.
Overload 1 of 2, '(value: { id: number | SQL<unknown> | Placeholder<string, any>; text: string | SQL<unknown> | Placeholder<string, any>; done?: boolean | SQL<unknown> | Placeholder<string, any> | undefined; }): PgInsertBase<...>', gave the following error.
Argument of type '{ text: string; done: false; }' is not assignable to parameter of type '{ id: number | SQL<unknown> | Placeholder<string, any>; text: string | SQL<unknown> | Placeholder<string, any>; done?: boolean | SQL<unknown> | Placeholder<string, any> | undefined; }'.
Property 'id' is missing in type '{ text: string; done: false; }' but required in type '{ id: number | SQL<unknown> | Placeholder<string, any>; text: string | SQL<unknown> | Placeholder<string, any>; done?: boolean | SQL<unknown> | Placeholder<string, any> | undefined; }'.
Overload 2 of 2, '(values: { id: number | SQL<unknown> | Placeholder<string, any>; text: string | SQL<unknown> | Placeholder<string, any>; done?: boolean | SQL<unknown> | Placeholder<string, any> | undefined; }[]): PgInsertBase<...>', gave the following error.
Object literal may only specify known properties, and 'text' does not exist in type '{ id: number | SQL<unknown> | Placeholder<string, any>; text: string | SQL<unknown> | Placeholder<string, any>; done?: boolean | SQL<unknown> | Placeholder<string, any> | undefined; }[]'.ts(2769)
import { integer, text, boolean, pgTable } from "drizzle-orm/pg-core";
export const todo = pgTable("todo_test", {
id: integer("id").primaryKey(),
text: text("text").notNull(),
done: boolean("done").default(false).notNull(),
});
import { integer, text, boolean, pgTable } from "drizzle-orm/pg-core";
export const todo = pgTable("todo_test", {
id: integer("id").primaryKey(),
text: text("text").notNull(),
done: boolean("done").default(false).notNull(),
});
7 replies