Tabish Zaidi
Tabish Zaidi

Reputation: 43

typescript error with MariaDB node.js for pool.getConnection

using mariadb npmjs version: 2.1.2

import mariadb from "mariadb";
const pool = mariadb.createPool({host: process.env.DBHOST, user: process.env.DBUSER, password: process.env.DBPASS, port: process.env.DBPORT, connectionLimit: process.env.DBCONNLIMIT, rowsAsArray: true });

pool.getConnection((err: any, conn: any) => {
        if (err) {
          console.log("not connected due to error: " + err);
        } else {
          console.log("connected ! connection id is " + conn.threadId);
          conn.end(); //release to pool
        }
      });

the getConnection portion is giving me typescript errors Expected 0 arguments, but got 1.ts(2554)

Even though mariadb package suggest it has types defined for typescript, however, I noticed their types are not correct based on the example in documentation.

my usage of pool.getConnection is coming straight from documentation example. This is the line in the types:

export interface Pool {
  /**
   * Retrieve a connection from pool.
   * Create a new one, if limit is not reached.
   * wait until acquireTimeout.
   */
  getConnection(): Promise<PoolConnection>;

At MariaDB/mariadb-connector-nodejs

Is there a way I could override this or should I create an issue in the github repo? I am not sure whether I'm looking at it correctly. Thanks.

Upvotes: 1

Views: 2636

Answers (1)

Diego Dupin
Diego Dupin

Reputation: 1348

MariaDB node.js connector implement "promise" implementation by default

see https://github.com/mariadb-corporation/mariadb-connector-nodejs#documentation

See promise documentation for detailed API.

Callback documentation describe the callback wrapper for compatibility with existing drivers.

I don't find the exact documentation part you refer to, but it seems to refer to callback implementation. Typescript descriptor use promise implementation only.

Upvotes: 1

Related Questions