diff --git a/test/types/connection.test.ts b/test/types/connection.test.ts index c5979663a20..bd099dec63a 100644 --- a/test/types/connection.test.ts +++ b/test/types/connection.test.ts @@ -54,6 +54,11 @@ expectType>(conn.transaction(async(res) => { return 'a'; }, { readConcern: 'majority' })); +expectType>(conn.withSession(async(res) => { + expectType(res); + return 'a'; +})); + expectError(conn.user = 'invalid'); expectError(conn.pass = 'invalid'); expectError(conn.host = 'invalid'); diff --git a/types/connection.d.ts b/types/connection.d.ts index 2f47bdc84e5..1ed08ad89e3 100644 --- a/types/connection.d.ts +++ b/types/connection.d.ts @@ -247,7 +247,7 @@ declare module 'mongoose' { /** Watches the entire underlying database for changes. Similar to [`Model.watch()`](/docs/api/model.html#model_Model-watch). */ watch(pipeline?: Array, options?: mongodb.ChangeStreamOptions): mongodb.ChangeStream; - withSession(executor: (session: ClientSession) => Promise): T; + withSession(executor: (session: ClientSession) => Promise): Promise; } }