From 561a5802e89b695abbbcb2e4cebfd235c480a684 Mon Sep 17 00:00:00 2001 From: tt-public <48979099+tt-public@users.noreply.github.com> Date: Tue, 25 Jun 2024 23:39:10 +0900 Subject: [PATCH 1/2] test: add type test for Connection.withSession --- test/types/connection.test.ts | 5 +++++ 1 file changed, 5 insertions(+) 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'); From cc63f6955ca4aa7b43b9c6ea880d55bbc01eecb4 Mon Sep 17 00:00:00 2001 From: tt-public <48979099+tt-public@users.noreply.github.com> Date: Tue, 25 Jun 2024 23:40:23 +0900 Subject: [PATCH 2/2] feat: fix return type of Connection.withSession --- types/connection.d.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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; } }