Skip to content

Commit

Permalink
Merge pull request #14690 from tt-public/feat/type-withsession
Browse files Browse the repository at this point in the history
types(connection): fix return type of withSession()
  • Loading branch information
vkarpov15 authored Jun 25, 2024
2 parents 31111f2 + cc63f69 commit f89868b
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 1 deletion.
5 changes: 5 additions & 0 deletions test/types/connection.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,11 @@ expectType<Promise<void>>(conn.transaction(async(res) => {
return 'a';
}, { readConcern: 'majority' }));

expectType<Promise<string>>(conn.withSession(async(res) => {
expectType<mongodb.ClientSession>(res);
return 'a';
}));

expectError(conn.user = 'invalid');
expectError(conn.pass = 'invalid');
expectError(conn.host = 'invalid');
Expand Down
2 changes: 1 addition & 1 deletion types/connection.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<ResultType extends mongodb.Document = any>(pipeline?: Array<any>, options?: mongodb.ChangeStreamOptions): mongodb.ChangeStream<ResultType>;

withSession<T = any>(executor: (session: ClientSession) => Promise<T>): T;
withSession<T = any>(executor: (session: ClientSession) => Promise<T>): Promise<T>;
}

}

0 comments on commit f89868b

Please sign in to comment.