fix(mongoose): Connection's aren't truly thenable

This commit is contained in:
Ethan Resnick
2018-06-13 03:33:56 -04:00
parent 0a08e47064
commit d4da3f6afa
2 changed files with 12 additions and 5 deletions
+5 -5
View File
@@ -1,4 +1,4 @@
// Type definitions for Mongoose 5.0.1
// Type definitions for Mongoose 5.0.2
// Project: http://mongoosejs.com/
// Definitions by: horiuchi <https://github.com/horiuchi>
// sindrenm <https://github.com/sindrenm>
@@ -97,7 +97,10 @@ declare module "mongoose" {
export function createConnection(): Connection;
export function createConnection(uri: string,
options?: ConnectionOptions
): Connection;
): Connection & {
then: Promise<Connection>["then"];
catch: Promise<Connection>["catch"];
};
/**
* Disconnects all connections.
@@ -403,9 +406,6 @@ declare module "mongoose" {
/** Expose the possible connection states. */
static STATES: any;
then: Promise<Connection>["then"];
catch: Promise<Connection>["catch"];
}
/*
+7
View File
@@ -131,6 +131,13 @@ mongoose.Connection.STATES.hasOwnProperty('');
conn1.on('data', cb);
conn1.addListener('close', cb);
// The connection returned by useDb is *not* thenable.
// From https://github.com/DefinitelyTyped/DefinitelyTyped/pull/26057#issuecomment-396150819
const getDB = async (tenant: string)=> {
return conn1.useDb(tenant);
};
/*
* section error/validation.js
* http://mongoosejs.com/docs/api.html#error-validation-js