Type error when inserting

Aim insert row to contactInformationTable My attempt
// schema.ts
import { blob, integer, sqliteTable, text } from 'drizzle-orm/sqlite-core';
import { generateId } from 'lucia';

export const userTable = sqliteTable('user', {
id: text('id')
.notNull()
.primaryKey()
.$default(() => generateId(15)),
hashedPassword: text('hashed_password').notNull(),
});

export const contactInformationTable = sqliteTable('contact_information', {
userId: text('user_id')
.notNull()
.unique()
.references(() => userTable.id),
firstName: text('first_name'),
});
// schema.ts
import { blob, integer, sqliteTable, text } from 'drizzle-orm/sqlite-core';
import { generateId } from 'lucia';

export const userTable = sqliteTable('user', {
id: text('id')
.notNull()
.primaryKey()
.$default(() => generateId(15)),
hashedPassword: text('hashed_password').notNull(),
});

export const contactInformationTable = sqliteTable('contact_information', {
userId: text('user_id')
.notNull()
.unique()
.references(() => userTable.id),
firstName: text('first_name'),
});
// serverFunction.ts
await db
.insert(contactInformationTable)
.values({
userId: user.id,
firstName,
})
// serverFunction.ts
await db
.insert(contactInformationTable)
.values({
userId: user.id,
firstName,
})
// package.json
"drizzle-orm": "^0.31.0",
"drizzle-kit": "^0.21.4",
// package.json
"drizzle-orm": "^0.31.0",
"drizzle-kit": "^0.21.4",
3 Replies
lettucebaran
lettucebaranOP7mo ago
Error
No overload matches this call.
Overload 1 of 2, '(value: { userId?: string | SQL<unknown> | Placeholder<string, any> | undefined; firstName?: string | SQL<unknown> | Placeholder<string, any> | null | undefined; }): SQLiteInsertBase<...>', gave the following error.
Type 'FormDataEntryValue | undefined' is not assignable to type 'string | SQL<unknown> | Placeholder<string, any> | null | undefined'.
Type 'File' is not assignable to type 'string | SQL<unknown> | Placeholder<string, any> | null | undefined'.
Type 'File' is missing the following properties from type 'Placeholder<string, any>': protected, getSQL
Overload 2 of 2, '(values: { userId?: string | SQL<unknown> | Placeholder<string, any> | undefined; firstName?: string | SQL<unknown> | Placeholder<string, any> | null | undefined; }[]): SQLiteInsertBase<...>', gave the following error.
Object literal may only specify known properties, and 'userId' does not exist in type '{ userId?: string | SQL<unknown> | Placeholder<string, any> | undefined; firstName?: string | SQL<unknown> | Placeholder<string, any> | null | undefined; }[]'.ts(2769)
No overload matches this call.
Overload 1 of 2, '(value: { userId?: string | SQL<unknown> | Placeholder<string, any> | undefined; firstName?: string | SQL<unknown> | Placeholder<string, any> | null | undefined; }): SQLiteInsertBase<...>', gave the following error.
Type 'FormDataEntryValue | undefined' is not assignable to type 'string | SQL<unknown> | Placeholder<string, any> | null | undefined'.
Type 'File' is not assignable to type 'string | SQL<unknown> | Placeholder<string, any> | null | undefined'.
Type 'File' is missing the following properties from type 'Placeholder<string, any>': protected, getSQL
Overload 2 of 2, '(values: { userId?: string | SQL<unknown> | Placeholder<string, any> | undefined; firstName?: string | SQL<unknown> | Placeholder<string, any> | null | undefined; }[]): SQLiteInsertBase<...>', gave the following error.
Object literal may only specify known properties, and 'userId' does not exist in type '{ userId?: string | SQL<unknown> | Placeholder<string, any> | undefined; firstName?: string | SQL<unknown> | Placeholder<string, any> | null | undefined; }[]'.ts(2769)
Question
and 'userId' does not exist in type '{ userId?: string | SQL<unknown> | Placeholder<string, any> | undefined; firstName?: string | SQL<unknown> | Placeholder<string, any> | null | undefined; }[]'.ts(2769)
I already pass userId when inserting, so why do I get this error?
Angelelz
Angelelz7mo ago
Your problem is overload 1 You have to make sure that the value that comes from the form is not a file
lettucebaran
lettucebaranOP7mo ago
interesting i typecasted all values to string, and overload 1 and 2 are both solved thanks a lot!
Want results from more Discord servers?
Add your server