Skip to content

Commit

Permalink
Merge pull request #9612 from alecgibson/ts-create-connection
Browse files Browse the repository at this point in the history
TS: Return `Connection` from `createConnection`
  • Loading branch information
vkarpov15 authored Dec 1, 2020
2 parents 07b1412 + 0d9e3c6 commit 7bf56aa
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 2 deletions.
2 changes: 1 addition & 1 deletion index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ declare module "mongoose" {
export var connections: Connection[];

/** Creates a Connection instance. */
export function createConnection(uri: string, options?: ConnectOptions): Promise<Connection>;
export function createConnection(uri: string, options?: ConnectOptions): Connection & Promise<Connection>;
export function createConnection(): Connection;
export function createConnection(uri: string, options: ConnectOptions, callback: (err: CallbackError, conn: Connection) => void): void;

Expand Down
4 changes: 3 additions & 1 deletion test/typescript/connection.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,6 @@ conn.openUri('mongodb://localhost:27017/test').then(() => console.log('Connected

createConnection('mongodb://localhost:27017/test', { useNewUrlParser: true }).then((conn: Connection) => {
conn.host;
});
});

createConnection('mongodb://localhost:27017/test').close();

0 comments on commit 7bf56aa

Please sign in to comment.