DefinitelyTyped / DefinitelyTyped

The repository for high quality TypeScript type definitions.
Other
48.49k stars 30.14k forks source link

[@types/mongodb] Property 'isConnected' does not exist on type 'Server' #43391

Closed fabiooshiro closed 3 years ago

fabiooshiro commented 4 years ago

Hi @rifler

import { MongoClient, Db } from "mongodb";
let db: Db = /*async getDb... */
db.serverConfig.isConnected()
error TS2339: Property 'isConnected' does not exist on type 'Server | ReplSet | Mongos'.
  Property 'isConnected' does not exist on type 'Server'.
rifler commented 4 years ago

You think I broke it in https://github.com/DefinitelyTyped/DefinitelyTyped/pull/43279 ?

peterblazejewicz commented 4 years ago

@fabiooshiro which version of driver api you're using?

fabiooshiro commented 4 years ago

Hi, the version is "@types/mongodb": "^3.5.3",

On Fri, Mar 27, 2020 at 6:11 PM Piotr Błażejewicz (Peter Blazejewicz) < notifications@github.com> wrote:

@fabiooshiro https://github.com/fabiooshiro which version of driver api you're using?

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/DefinitelyTyped/DefinitelyTyped/issues/43391#issuecomment-605316825, or unsubscribe https://github.com/notifications/unsubscribe-auth/AABVNEHMZKP5NPE3IVWVAG3RJUI7DANCNFSM4LUDE56A .

aldo-sanchez commented 4 years ago

I'm seeing the same with client.isConnected()

Property 'isConnected' does not exist on type 'Mongo'.

peterblazejewicz commented 4 years ago

I'll try to be on the same page, I believe MongoClient.isConnected({}?) method works OK, with current types and driver 3.6,

const client = new MongoClient('mongodb://localhost:27017', {
  useUnifiedTopology: true,
});
(async () => {
    await client.connect()
    if (client.isConnected()) {
        await client.close();
    }
})();

The server fires events, including 'connected', has no direct API on the surface to check connection status IMO: http://mongodb.github.io/node-mongodb-native/3.6/api/Server.html#event:connect (I could be wrong on this, never had to write a code to check the server status that way, client is enough)

orta commented 3 years ago

Hi thread, we're moving DefinitelyTyped to use GitHub Discussions for conversations the @types modules in DefinitelyTyped.

To help with the transition, we're closing all issues which haven't had activity in the last 6 months, which includes this issue. If you think closing this issue is a mistake, please pop into the TypeScript Community Discord and mention the issue in the definitely-typed channel.