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

Typing error in v3.0.0-rc1 Interface 'PoolConnection' cannot simultaneously extend types 'PoolConnection' and 'Connection' #1722

Closed
abentpole opened this issue Dec 2, 2022 · 18 comments

Comments

@abentpole
Copy link

abentpole commented Dec 2, 2022

Hello, I was giving v3.0.0-rc1 a spin and noticed the following issue:

node_modules/mysql2/index.d.ts:86:18 - error TS2320: Interface 'PoolConnection' cannot simultaneously extend types 'PoolConnection' and 'Connection'.
  Named property 'execute' of types 'PoolConnection' and 'Connection' are not identical.

86 export interface PoolConnection extends mysql.PoolConnection, Connection {
                    ~~~~~~~~~~~~~~

This was noticed with Typescript version 4.5.5, though I also just tested with 4.9.3 and confirmed it occurs there too.
Edit: A note that for this to come up when the library is in use; ensure skipLibCheck isn't true.

@abentpole abentpole changed the title Typing error in v3.0.0-rc1 Typing error in v3.0.0-rc1 Interface 'PoolConnection' cannot simultaneously extend types 'PoolConnection' and 'Connection' Dec 2, 2022
@sidorares
Copy link
Owner

could you post a snippet of typescript code to reproduce the error @abentpole ?

@abentpole
Copy link
Author

@sidorares Just a matter of importing the promise version of the library in a Typescript project with "skipLibCheck": false.

So to replicate it:

  1. npm init
  2. npm i mysql2@3.0.0-rc.1 typescript
  3. npx tsc --init
  4. Open tsconfig.json, go to the bottom and set "skipLibCheck" to false
  5. Make a file, index.ts, with the content import * as mysql from 'mysql2/promise';
  6. npx tsc and observe the error

@CComparon
Copy link

Same problem happening to me. Both with typescript": "4.7.4" and typescript": "4.9.4".

@HofmannZ
Copy link

Same issue with version 3.0.1.

@rohan-rao-qp
Copy link

Same issue with typescript version 4.9.4. For now, the only way I found to get it running was by setting skipLibCheck: true in tsconfig.

@khanfx
Copy link

khanfx commented Jan 24, 2023

So for a concrete example -

When faced with this error:

node_modules/mysql2/index.d.ts:86:18 - error TS2320: Interface 'PoolConnection' cannot simultaneously extend types 'PoolConnection' and 'Connection'.
  Named property 'unprepare' of types 'PoolConnection' and 'Connection' are not identical.

86 export interface PoolConnection extends mysql.PoolConnection, Connection {
                    ~~~~~~~~~~~~~~

The items indicated are:

From mysql2\index.d.ts:

  unprepare(sql: string): mysql.PrepareStatementInfo;

From mysql2\typings\mysql\lib\Connection.d.ts:

    unprepare(sql: string): any;

Experimented a little but unsure how to progress.

This seems to be the item over in Typescript that would make this work as specced, but clearly not being built any time soon:

microsoft/TypeScript#16936

@eschneor
Copy link

Get this issue, too, when trying to update from "mysql2": "2.3.3" to "mysql2": "3.1.2", using "typescript": "4.9.5".

Is there an ETA to get this in place? Thanks!

@oilop9000
Copy link

Same problem here!

@HofmannZ
Copy link

I don't think @sidorares is going to fix this. See #1792.

@sidorares
Copy link
Owner

I really want to fix, just don't have enough time. If anyone wants to help that would be great

@eschneor
Copy link

So, for now the solution is to stick with an old version? (before v3.0.0)

@sidorares
Copy link
Owner

So, for now the solution is to stick with an old version? (before v3.0.0)

  • stay on pre v3
  • "skipLibCheck": true,
  • have your own local types that fix the errors
  • submit a PR to fix on mysql2 side, wait it to be reviewed / merged / released

tomrijnbeek added a commit to clanquest/questbot that referenced this issue Mar 2, 2023
tomrijnbeek added a commit to clanquest/questbot that referenced this issue Mar 13, 2023
* 🔥 Remove webhook functionality

* 🚧 Reimplement commands

* 🔥 Remove unnecessary dependencies

* 📝 Update README

* ⬇ Downgrade mysql2 to fix build error.

See sidorares/node-mysql2#1722

* Remove 14.x node support

* 🐛 Update pm2 ecosystem

* 🔍 Replace tslint with eslint

* 🐛 Ensure clean works on first attempt

* ⬆ Increase node version on CircleCI

* 📚 Improve command architecture

* 💄 Finalize linted code

* 🔥 Remove ts-clean in favour of --clean flag in tsc

* 🐛 Work in progress to fix running

* 🐛 Fix all newly introduced bugs based on testing

* Add members and messages intents to client

* Update node image
@wellwelwel
Copy link
Sponsor Collaborator

wellwelwel commented Apr 8, 2023

Once the PoolConnection.d.ts has already declared extending the Connection:

declare class PoolConnection extends Connection {
    connection: Connection;
    release(): void;
}

Then it doesn't need to re extends the Connection in index.d.ts #86 like:

export interface PoolConnection extends mysql.PoolConnection, Connection {
  promise(promiseImpl?: PromiseConstructor): PromisePoolConnection;
}

So, just by removing the Connection from extends in index.d.ts, it will work:

export interface PoolConnection extends mysql.PoolConnection {
  promise(promiseImpl?: PromiseConstructor): PromisePoolConnection;
}

I cloned the 3.2.0 release and tested it in a real use, it works perfectly.

@sidorares, can I submit a PR for a change that is too small?

@sidorares
Copy link
Owner

sidorares commented Apr 13, 2023

@wellwelwel should be in npm as v3.2.1 in a minute

#1951

https://github.com/sidorares/node-mysql2/releases/tag/v3.2.1

@sidorares
Copy link
Owner

@abentpole give v3.2.1 a try and if the issue is fixed we can close it

@HofmannZ
Copy link

Does not seem to fix it:

> tsc -p .

node_modules/.pnpm/mysql2@3.2.1/node_modules/mysql2/index.d.ts:10:18 - error TS2430: Interface 'import("/Users/zinohofmann/Projects/github.com/expatfile/firestore-service/node_modules/.pnpm/mysql2@3.2.1/node_modules/mysql2/index").Connection' incorrectly extends interface 'import("/Users/zinohofmann/Projects/github.com/expatfile/firestore-service/node_modules/.pnpm/mysql2@3.2.1/node_modules/mysql2/typings/mysql/index").Connection'.
  The types returned by 'promise(...)' are incompatible between these types.
    Type 'Connection' is missing the following properties from type 'Promise<Connection>': then, catch, finally, [Symbol.toStringTag]

10 export interface Connection extends mysql.Connection {
                    ~~~~~~~~~~

node_modules/.pnpm/mysql2@3.2.1/node_modules/mysql2/index.d.ts:86:18 - error TS2430: Interface 'import("/Users/zinohofmann/Projects/github.com/expatfile/firestore-service/node_modules/.pnpm/mysql2@3.2.1/node_modules/mysql2/index").PoolConnection' incorrectly extends interface 'import("/Users/zinohofmann/Projects/github.com/expatfile/firestore-service/node_modules/.pnpm/mysql2@3.2.1/node_modules/mysql2/typings/mysql/index").PoolConnection'.
  The types returned by 'promise(...)' are incompatible between these types.
    Type 'PoolConnection' is missing the following properties from type 'Promise<Connection>': then, catch, finally, [Symbol.toStringTag]

86 export interface PoolConnection extends mysql.PoolConnection {
                    ~~~~~~~~~~~~~~

node_modules/.pnpm/mysql2@3.2.1/node_modules/mysql2/index.d.ts:90:18 - error TS2430: Interface 'Pool' incorrectly extends interface 'Connection'.
  The types returned by 'promise(...)' are incompatible between these types.
    Type 'Pool' is missing the following properties from type 'Promise<Connection>': then, catch, finally, [Symbol.toStringTag]

90 export interface Pool extends mysql.Connection {
                    ~~~~


Found 3 errors in the same file, starting at: node_modules/.pnpm/mysql2@3.2.1/node_modules/mysql2/index.d.ts:10

 ELIFECYCLE  Command failed with exit code 1.

@wellwelwel
Copy link
Sponsor Collaborator

wellwelwel commented Apr 14, 2023

@HofmannZ

This error is not a part of this issue. I suggest you to look at the issue #1936.
The PR #1949 is who is causing this error and was merged together in 3.2.1 release 😕
Anyway, I submited a PR to fix it too in #1955.

@abentpole
Copy link
Author

Sorry @sidorares, I missed your first ping. Gave this a test and can confirm it doesn't happen in v3.3.1.

Thanks!

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

9 participants