DrizzleORM with JSDoc (insert problem)

Hi, I am trying to use drizzle with jsdoc in my project. I created the schema and everything works when I run it but for some reason jsdoc in VSCode is complaining when I try to insert anything besides the fields that must be specified like primary keys and fields with .notNull().unique(). Any ideas why this might happen? Here is a part of my schema:
// @ts-check

const guilds = mysqlTable('guilds', {
id: varchar('guild_id', { length: 20 }).primaryKey(),
whitelisted: boolean('whitelisted').notNull().default(false),
verifiedRoleId: varchar('verified_role_id', { length: 20 }),
unverifiedRoleId: varchar('unverified_role_id', { length: 20 }),
});
exports.guilds = guilds;

/**
* @typedef {typeof guilds.$inferSelect} GuildRecord
*/
// @ts-check

const guilds = mysqlTable('guilds', {
id: varchar('guild_id', { length: 20 }).primaryKey(),
whitelisted: boolean('whitelisted').notNull().default(false),
verifiedRoleId: varchar('verified_role_id', { length: 20 }),
unverifiedRoleId: varchar('unverified_role_id', { length: 20 }),
});
exports.guilds = guilds;

/**
* @typedef {typeof guilds.$inferSelect} GuildRecord
*/
And if I try to do something like:
// @ts-check

const mysql = require('mysql2');
const { drizzle } = require('drizzle-orm/mysql2');
const { guilds } = require('./schema.js');

const pool = mysql.createPool({
// ...
});

const db = drizzle(pool);
db.insert(guilds).values({ id: 'someid', whitelisted: true, });
// @ts-check

const mysql = require('mysql2');
const { drizzle } = require('drizzle-orm/mysql2');
const { guilds } = require('./schema.js');

const pool = mysql.createPool({
// ...
});

const db = drizzle(pool);
db.insert(guilds).values({ id: 'someid', whitelisted: true, });
it underlines .values, I don't understand why. The error it shows is:
No overload matches this call.
No overload matches this call.
Any ideas would be greatly appreciated :)
3 Replies
rdobovic
rdobovicOP4mo ago
Here is the full error:
No overload matches this call.
Overload 1 of 2, '(value: { id: string | SQL<unknown> | Placeholder<string, any>; }): MySqlInsertBase<MySqlTableWithColumns<{ name: "guilds"; schema: undefined; columns: { id: MySqlColumn<{ name: "guild_id"; tableName: "guilds"; dataType: "string"; ... 10 more ...; generated: GeneratedColumnConfig<...>; }, object>; whitelisted: MySqlColumn<...>; verifiedRoleId: MySqlColumn<...>; unverifiedRoleId: MySqlColumn<...>; }; dialect: "mysql"; }>, ... 4 more ..., never>', gave the following error.
Object literal may only specify known properties, and 'whitelisted' does not exist in type '{ id: string | SQL<unknown> | Placeholder<string, any>; }'.
Overload 2 of 2, '(values: { id: string | SQL<unknown> | Placeholder<string, any>; }[]): MySqlInsertBase<MySqlTableWithColumns<{ name: "guilds"; schema: undefined; columns: { id: MySqlColumn<{ name: "guild_id"; tableName: "guilds"; dataType: "string"; ... 10 more ...; generated: GeneratedColumnConfig<...>; }, object>; whitelisted: MySqlColumn<...>; verifiedRoleId: MySqlColumn<...>; unverifiedRoleId: MySqlColumn<...>; }; dialect: "mysql"; }>, ... 4 more ..., never>', gave the following error.
Object literal may only specify known properties, and 'id' does not exist in type '{ id: string | SQL<unknown> | Placeholder<string, any>; }[]'.ts(2769)
No overload matches this call.
Overload 1 of 2, '(value: { id: string | SQL<unknown> | Placeholder<string, any>; }): MySqlInsertBase<MySqlTableWithColumns<{ name: "guilds"; schema: undefined; columns: { id: MySqlColumn<{ name: "guild_id"; tableName: "guilds"; dataType: "string"; ... 10 more ...; generated: GeneratedColumnConfig<...>; }, object>; whitelisted: MySqlColumn<...>; verifiedRoleId: MySqlColumn<...>; unverifiedRoleId: MySqlColumn<...>; }; dialect: "mysql"; }>, ... 4 more ..., never>', gave the following error.
Object literal may only specify known properties, and 'whitelisted' does not exist in type '{ id: string | SQL<unknown> | Placeholder<string, any>; }'.
Overload 2 of 2, '(values: { id: string | SQL<unknown> | Placeholder<string, any>; }[]): MySqlInsertBase<MySqlTableWithColumns<{ name: "guilds"; schema: undefined; columns: { id: MySqlColumn<{ name: "guild_id"; tableName: "guilds"; dataType: "string"; ... 10 more ...; generated: GeneratedColumnConfig<...>; }, object>; whitelisted: MySqlColumn<...>; verifiedRoleId: MySqlColumn<...>; unverifiedRoleId: MySqlColumn<...>; }; dialect: "mysql"; }>, ... 4 more ..., never>', gave the following error.
Object literal may only specify known properties, and 'id' does not exist in type '{ id: string | SQL<unknown> | Placeholder<string, any>; }[]'.ts(2769)
rdobovic
rdobovicOP4mo ago
So in this example, .$inferInsert looks like this:
No description
rdobovic
rdobovicOP4mo ago
Ok I managed to find the solution, when I added "strict": true to my jsconfig.json file it worked
Want results from more Discord servers?
Add your server