The class below throws the error
Type 'typeof import("mongoose")' is missing the following properties from type 'Db': serverConfig, bufferMaxEntries, databaseName, options, and 37 more.
I cannot find out what the return type of mongoose.connect is.
import mongoose from "mongoose";
import {Db} from "mongodb";
interface MongoDbConfig {
server: String,
port: String,
dbName: String;
}
// TODO: make singelton
class MongoDb {
private db : Db;
private _server : String;
private _port : String;
private _dbName : String;
constructor(config: MongoDbConfig){
this._server = config.server;
this._port = config.port;
this._dbName = config.dbName
}
public async connect() {
const uri = "mongodb://"+this._server+":"+this._port+"/"+this._dbName;
this.db = await mongoose.connect(uri, { useNewUrlParser: true }); // error
console.log(typeof this.db)
console.log("Connected to db");
return this.db;
}
public getDb(){
return this.db;
}
}