MongoDB Node driver. Inconsistent TS types and results

I just now “yarn add mongodb” to a node TS app and attempted the following.

  const databasesList  = await client.db().admin().listDatabases();

The type for listDatabases() is Promise<string[] | Document []>, neither of which match the actual result of what is returned when coercing the result to “any”.

Is the TS support for this library any good?

Hi and yes, I can confirm this. Basically the response to the client.db().admin().listDatabases() request has not changed compared to previous versions but the typescript-types provided by the new driver are entirely wrong. I’ve tried version 4.1.2. How to deal with this? Is there any remedy in sight?
thx, Thomas.

Hello @Chris_Lincoln and @Thomas_B, thank you for getting in touch about this.

We have merged in a fix to correct the typings for this method and it will go out in our next release 4.1.3, which should come within the next couple of weeks:

Should you encounter any further issues using the driver, TS or otherwise, please let us know.

1 Like

This topic was automatically closed 5 days after the last reply. New replies are no longer allowed.