Typescript Error when creating MySQL db pool

Hi Everyone,

I'm getting the following error when creating a database:
kysely Type '() => Promise<Pool>' is not assignable to type 'MysqlPool | (() => Promise<MysqlPool>)'

I'm using the following code:
// db.ts
import {
  Kysely,
  MysqlDialect,
}                     from 'kysely'
import { createPool } from 'mysql2'
import {
  DB_HOST,
  DB_PORT,
  DB_USER,
  DB_PASS,
  DB_NAME
}                     from '$env/static/private'
import type { DB }    from 'kysely-codegen'

export const mysqlPoolOpts = {
  database:           DB_NAME,
  host:               DB_HOST,
  port:               parseInt(DB_PORT),
  user:               DB_USER,
  password:           DB_PASS,
  waitForConnections: true,
  connectionLimit:    10,
  // maxIdle:            10, // max idle connections, the default value is the same as `connectionLimit`
  // idleTimeout:        60000, // idle connections timeout, in milliseconds, the default value 60000
  queueLimit:         0
}

export const db = new Kysely<DB>({
  dialect: new MysqlDialect({
    pool: async () => createPool(mysqlPoolOpts)
//   ^^ -- error here
  })
})

(cont'd in following message ...)
Was this page helpful?