You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
When using a Promise Pool, and subscribing to events (e.g.pool.on('acquire', (connection) => {})) the connection object does not match the type.
In the types, the connection type is exposed as a Promise PoolConnection, where in reality there is no conversion from the original, and so it's actually a base PoolConnection type. Meaning if I want to use it, i have to call the Promise() helper, which isn't on the Promise PoolConnection type.
This is causing a bit of confusion on my end, and i'm not sure what the expected behaviour is? Should these be converted to PromisePoolConnections, or should the types be updated appropriately?
import { PoolConnection } from 'mysql2'
import mysql from 'mysql2/promise'
// this is a PromisePool
const pool = mysql.createPool(options);
// PoolConnection here is NOT a PoolConnection from the Promise lib
// but typescript thinks it is, and so is giving an error.
pool.on('acquire', async (connection: PoolConnection) => {
await connection.promise().beginTransaction();
});
The text was updated successfully, but these errors were encountered:
This fixes a number of small type errors compared to the underlying code. This is likely a breaking change for some users as it would have required some working around.
Should fixsidorares#3238 and sidorares#2667
When using a Promise Pool, and subscribing to events (e.g.
pool.on('acquire', (connection) => {})
) the connection object does not match the type.In the types, the connection type is exposed as a Promise PoolConnection, where in reality there is no conversion from the original, and so it's actually a base PoolConnection type. Meaning if I want to use it, i have to call the
Promise()
helper, which isn't on the Promise PoolConnection type.This is causing a bit of confusion on my end, and i'm not sure what the expected behaviour is? Should these be converted to PromisePoolConnections, or should the types be updated appropriately?
The text was updated successfully, but these errors were encountered: