Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(NODE-4108): improve return type for withTransaction() #3203

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions src/sessions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -467,10 +467,10 @@ export class ClientSession extends TypedEventEmitter<ClientSessionEvents> {
* @param fn - A lambda to run within a transaction
* @param options - Optional settings for the transaction
*/
withTransaction<T = void>(
fn: WithTransactionCallback<T>,
withTransaction(
fn: WithTransactionCallback<void>,
options?: TransactionOptions
): ReturnType<typeof fn> {
): Promise<void> {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Even though the return type is meant to be an internal command result we should reflect what's actually returned here and we can fix this in the next major version. This function will return the command result if the transaction commits successfully, it will throw if it aborts and it will return undefined if it's aborted manually within the user provided function, so it's important that the result at least demonstrate that it can be truthy or not under the right circumstance.
So we should put the type in here that matches the actual result from the function, and add tests to prevent a regression.

const startTime = now();
return attemptTransaction(this, startTime, fn, options);
}
Expand Down