Skip to content

Commit

Permalink
fix(NODE-5592): withTransaction return type (#3846)
Browse files Browse the repository at this point in the history
  • Loading branch information
W-A-James committed Aug 28, 2023
1 parent 91152b9 commit 05d2725
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 8 deletions.
2 changes: 1 addition & 1 deletion src/sessions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -453,7 +453,7 @@ export class ClientSession extends TypedEventEmitter<ClientSessionEvents> {
async withTransaction<T = any>(
fn: WithTransactionCallback<T>,
options?: TransactionOptions
): Promise<Document | undefined> {
): Promise<T> {
const startTime = now();
return attemptTransaction(this, startTime, fn, options);
}
Expand Down
12 changes: 5 additions & 7 deletions test/types/community/transaction.test-d.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
import { type ClientSession, MongoClient, ReadConcern } from '../../mongodb';
import { expectType } from 'tsd';

import { type ClientSession, type InsertOneResult, MongoClient, ReadConcern } from '../../mongodb';

// TODO(NODE-3345): Improve these tests to use expect assertions more

Expand Down Expand Up @@ -111,11 +113,7 @@ try {
client.withSession(session => runTransactionWithRetry(updateEmployeeInfo, client, session));

const col = client.db('test').collection<{ _id: string }>('col');
const ok = await session.withTransaction(async () => {
const insertResult = await session.withTransaction(async () => {
return await col.insertOne({ _id: 'one' }, { session });
});
if (ok) {
console.log('success');
} else {
console.log('nothing done');
}
expectType<InsertOneResult<{ _id: string }>>(insertResult);

0 comments on commit 05d2725

Please sign in to comment.