DT
Drizzle Team•4mo ago
Tomathy

No overload matches this call

I'm sorry that I'm already the 4th person with this sort of post, but the other posts didn't really help me out. I'm having an issue where it's sayig a certain attribute isn't in the type generated, but I don't see why not, and when I run the code it does work
await db.insert(clients).values({
name: faker.person.fullName(),
nif: faker.number.int({min: 100000000, max: 999999999}).toString(),
password: faker.internet.password(),
email: faker.internet.email(),
activity: client_activity[faker.number.int({min: 0, max: 2})],
obs: faker.helpers.arrayElement(['', faker.lorem.sentence()]),
services: faker.number.int({min: 1, max: services.length})
})
await db.insert(clients).values({
name: faker.person.fullName(),
nif: faker.number.int({min: 100000000, max: 999999999}).toString(),
password: faker.internet.password(),
email: faker.internet.email(),
activity: client_activity[faker.number.int({min: 0, max: 2})],
obs: faker.helpers.arrayElement(['', faker.lorem.sentence()]),
services: faker.number.int({min: 1, max: services.length})
})
Here's the schema:
//Clients table
export const clients = pgTable("clients",{
id: serial("id").primaryKey(),
name: varchar("name", { length: 256 }).notNull(),
nif: char("nif", { length: 9}).unique().notNull(),
password: bytea("password").unique().notNull(),
email: varchar("email", { length: 256}).unique(),
rf_taxrep: rfEnum("rf_taxrep"),
activity: activityEnum("activity").notNull(),
obs: text("obs"),
services: serial("services").references(() => service.id, {onDelete: "cascade"}),
})
//Clients table
export const clients = pgTable("clients",{
id: serial("id").primaryKey(),
name: varchar("name", { length: 256 }).notNull(),
nif: char("nif", { length: 9}).unique().notNull(),
password: bytea("password").unique().notNull(),
email: varchar("email", { length: 256}).unique(),
rf_taxrep: rfEnum("rf_taxrep"),
activity: activityEnum("activity").notNull(),
obs: text("obs"),
services: serial("services").references(() => service.id, {onDelete: "cascade"}),
})
Here's the error: No overload matches this call. Overload 2 of 2, '(values: { name: string | SQL<unknown> | Placeholder<string, any>; nif: string | SQL<unknown> | Placeholder<string, any>; password: SQL<unknown> | Buffer | Placeholder<...>; ... 5 more ...; services?: number | ... 2 more ... | undefined; }[]): PgInsertBase<...>', gave the following error. Object literal may only specify known properties, and 'name' does not exist in type '{ name: string | SQL<unknown> | Placeholder<string, any>; nif: string | SQL<unknown> | Placeholder<string, any>; password: SQL<unknown> | Buffer | Placeholder<...>; ... 5 more ...; services?: number | ... 2 more ... | undefined; }[]'.
9 Replies
Mario564
Mario564•4mo ago
@Tomathy Are you using a monorepo?
Tomathy
TomathyOP•4mo ago
no, just a single project
Mario564
Mario564•4mo ago
I see a bytea type that isn't part of Drizzle. I assume that's a custom type, what's the definition for that type?
Tomathy
TomathyOP•4mo ago
const bytea = customType<{ data: Buffer; notNull: false; default: false }>({
dataType() {
return "bytea";
},
});
const bytea = customType<{ data: Buffer; notNull: false; default: false }>({
dataType() {
return "bytea";
},
});
From the error message, it seems it's not recognizing name as an attribute :/
Mario564
Mario564•4mo ago
Just to confirm that the bytea type isn't causing issues, can you change the data attribute to string and see if there's still type errors?
Tomathy
TomathyOP•4mo ago
Tried it, but gives the same error but for a different attribute? It's so weird seeing as the first error was for "name" and not the bytea attribute. Nw it's just pointing out the enum 🤔 Here's the new schema:
export const clients = pgTable("clients",{
id: serial("id").primaryKey(),
name: varchar("name", { length: 256 }).notNull(),
nif: char("nif", { length: 9}).unique().notNull(),
password: varchar("password", {length: 256}).unique().notNull(),
email: varchar("email", { length: 256}).unique(),
rf_taxrep: rfEnum("rf_taxrep"),
activity: activityEnum("activity").notNull(),
obs: text("obs"),
services: serial("services").references(() => service.id, {onDelete: "cascade"}),
})
export const clients = pgTable("clients",{
id: serial("id").primaryKey(),
name: varchar("name", { length: 256 }).notNull(),
nif: char("nif", { length: 9}).unique().notNull(),
password: varchar("password", {length: 256}).unique().notNull(),
email: varchar("email", { length: 256}).unique(),
rf_taxrep: rfEnum("rf_taxrep"),
activity: activityEnum("activity").notNull(),
obs: text("obs"),
services: serial("services").references(() => service.id, {onDelete: "cascade"}),
})
Here's the new error: No overload matches this call. Overload 1 of 2, '(value: { name: string | SQL<unknown> | Placeholder<string, any>; nif: string | SQL<unknown> | Placeholder<string, any>; password: string | SQL<unknown> | Placeholder<...>; ... 5 more ...; services?: number | ... 2 more ... | undefined; }): PgInsertBase<...>', gave the following error. Type 'string' is not assignable to type 'SQL<unknown> | "ATIVO" | "NÃO ATIVO" | "SUSPENSO" | Placeholder<string, any>'. Overload 2 of 2, '(values: { name: string | SQL<unknown> | Placeholder<string, any>; nif: string | SQL<unknown> | Placeholder<string, any>; password: string | SQL<unknown> | Placeholder<...>; ... 5 more ...; services?: number | ... 2 more ... | undefined; }[]): PgInsertBase<...>', gave the following error. Object literal may only specify known properties, and 'name' does not exist in type '{ name: string | SQL<unknown> | Placeholder<string, any>; nif: string | SQL<unknown> | Placeholder<string, any>; ... (Discord limit)
Mario564
Mario564•4mo ago
I think it might have to do with one of the two enum fields In the insert statement I see this:
activity: client_activity[faker.number.int({min: 0, max: 2})],
activity: client_activity[faker.number.int({min: 0, max: 2})],
My guess is that client_activity[faker.number.int({min: 0, max: 2})] returns type string instead of the exact type the enum is looking for
Tomathy
TomathyOP•4mo ago
but the enum is composed of strings. Is there a way to export/import the enums type and how do I insert enum values into the table?
Mario564
Mario564•4mo ago
You can do something like this:
const client_activity = ['ATIVO', 'NÃO ATIVO', 'SUSPENSO'] as const;
const activityEnum = pgEnum(/* Enum name */, client_activity);
const client_activity = ['ATIVO', 'NÃO ATIVO', 'SUSPENSO'] as const;
const activityEnum = pgEnum(/* Enum name */, client_activity);
You might get a type error with faker.number.int({min: 0, max: 2}), in that case you can just cast:
client_activity[faker.number.int({min: 0, max: 2}) as keyof client_activity]
client_activity[faker.number.int({min: 0, max: 2}) as keyof client_activity]
Want results from more Discord servers?
Add your server