#What is the type for createPool().promise() function in node-mysql2

12 messages · Page 1 of 1 (latest)

gloomy lotus
#

I have the following code which connects to a MySQL database:

import { Connection, createPool } from 'mysql2'
import { PromisePoolConnection } from 'mysql2/promise'
import Pool from 'mysql2/typings/mysql/lib/Pool'

const poolOptions: Pool.PoolOptions = {
    host: 'localhost',
    user: 'root',
    database: 'node-complete',
    password: 'password'
}

const pool: PromisePoolConnection = createPool(poolOptions).promise()

export default pool

I am unsure what the correct type for pool is. Is it PromisePoolConnection or something else? I'm really confused.

Any help would be appreciated.

mental bough
#

you should do import { createPool } from 'mysql2/promise'

gloomy lotus
#

and then what

#

oh ok

#

then I get an error saying promise doesn't exist on type pool

mental bough
#

not needed anymore

gloomy lotus
#

ah ok, yeah it does automatically return a promise just realized

#

thanks man...

#

/close

#

/help close

mental bough
#

!resolve

surreal sorrelBOT
#

:warning: Only the asker can change the status of a help post