node-mysql2: Typing error in v3.0.0-rc1 Interface 'PoolConnection' cannot simultaneously extend types 'PoolConnection' and 'Connection'

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.

About this issue

  • Original URL
  • State: closed
  • Created 2 years ago
  • Reactions: 12
  • Comments: 18 (5 by maintainers)

Commits related to this issue

Most upvoted comments

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

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

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

Thanks!

@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

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.

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?

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