Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

type error in v3.1.0 #1816

Closed
sdg9670 opened this issue Jan 31, 2023 · 7 comments
Closed

type error in v3.1.0 #1816

sdg9670 opened this issue Jan 31, 2023 · 7 comments

Comments

@sdg9670
Copy link

sdg9670 commented Jan 31, 2023

I couldn't find connection.promise()

mysql.createConnection().promise()
@fated-x
Copy link

fated-x commented Feb 9, 2023

I too am experiencing this issue. The root cause appears to be the fact that /node_modules/mysql2/typings/mysql/lib/Pool.d.ts declared Pool class has a promise property that returns an any type:

Line 74: promise(promiseImpl?: any): any;

My Temporary Workaround (Solution):

  1. Revert the mysql2 dependency back to version 2.3.3. The pool.promise() in this version is typed in /node_modules/mysql2/index.d.ts on line 151 and will work as expected because it returns a PromisePool:
promise(promiseImpl?: PromiseConstructor): PromisePool;

@anders8
Copy link

anders8 commented Mar 14, 2023

I originally experienced a similar issue with 3.0.0 and like @fated-x I reverted, to the 2.2.5 I was using in my case. I just tried 3.2.0 and it's compiling without errors and making connections without apparent trouble.

However, I'm using mysql.createPool() not mysql.createConnection()

@marcellino-ornelas
Copy link

marcellino-ornelas commented Mar 14, 2023

Im using 3.2.0 and im getting a error when trying to use promise on connection

Property 'promise' does not exist on type 'Connection'.ts(2339)

import { createConnection, Connection } from 'mysql2';
import { config } from '@src/config';

export const db: Connection = createConnection(config.db);

db.promise(); // <---- error

@tristan-nsg
Copy link

I'm still getting this issue on 3.3.0

@wellwelwel
Copy link
Collaborator

wellwelwel commented May 10, 2023

@tristan-nsg

Look at this fix:

This PR changes are relatively extensive (especially the automated tests to prevent new changes from breaking the typings again), so this review cannot be rushed 🙋🏻‍♂️

@wellwelwel

This comment was marked as outdated.

@wellwelwel
Copy link
Collaborator

After version ^3.3.5, you can follow this example:

const db = mysql.createConnection(access).promise();
{
/** Overload: execute(sql) */
const [results, fields] = await db.execute(sql);
console.log(results, fields);
}


I'm closing this Issue, but feel free to ask anything 🙋🏻‍♂️

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

7 participants