Skip to content

Commit f89868b

Browse files
authored
Merge pull request #14690 from tt-public/feat/type-withsession
types(connection): fix return type of withSession()
2 parents 31111f2 + cc63f69 commit f89868b

File tree

2 files changed

+6
-1
lines changed

2 files changed

+6
-1
lines changed

test/types/connection.test.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,11 @@ expectType<Promise<void>>(conn.transaction(async(res) => {
5454
return 'a';
5555
}, { readConcern: 'majority' }));
5656

57+
expectType<Promise<string>>(conn.withSession(async(res) => {
58+
expectType<mongodb.ClientSession>(res);
59+
return 'a';
60+
}));
61+
5762
expectError(conn.user = 'invalid');
5863
expectError(conn.pass = 'invalid');
5964
expectError(conn.host = 'invalid');

types/connection.d.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -247,7 +247,7 @@ declare module 'mongoose' {
247247
/** Watches the entire underlying database for changes. Similar to [`Model.watch()`](/docs/api/model.html#model_Model-watch). */
248248
watch<ResultType extends mongodb.Document = any>(pipeline?: Array<any>, options?: mongodb.ChangeStreamOptions): mongodb.ChangeStream<ResultType>;
249249

250-
withSession<T = any>(executor: (session: ClientSession) => Promise<T>): T;
250+
withSession<T = any>(executor: (session: ClientSession) => Promise<T>): Promise<T>;
251251
}
252252

253253
}

0 commit comments

Comments
 (0)