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

types(model): fix type of options of Model.aggregate #12933

Merged
merged 1 commit into from Feb 4, 2023

Conversation

ghost91-
Copy link
Contributor

Summary

This change adjusts the type of the options parameter of Model.aggregate to be the AggregateOptions type from mongoose, instead of the one from mongodb. The aggregate method just passes this parameter on to Aggregate.option, which is already typed to accept the AggregateOptions type from mongoose, so this seems like the correct choice.

The 2 types mostly seem to be compatible anyways, but there is a small inconsistency that makes them incompatible: mongodb.AggregateOptions specifies that the session property may be a ClientSession, or undefined (but not null), while the AggregateOptions type from mongoose also allows null. So maybe that also should simply be aligned.

Copy link
Collaborator

@vkarpov15 vkarpov15 left a comment

Choose a reason for hiding this comment

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

This should work fine, but to reduce the risk of any backwards breaking changes, can we change AggregateOptions to something like the following?

interface AggregateOptions extends Omit<mongodb.AggregateOptions, 'session'>, SessionOption {
    [key: string]: any;
  }

That seems to work fine, and makes it so that there's no chance we missed an option from mongodb.AggregateOptions.

@ghost91-
Copy link
Contributor Author

I have incorporated the suggestion. Before doing so, I have manually verified that there are no differences between the 2 AggregateOptions types, aside from allowing null as the session property.

Copy link
Collaborator

@vkarpov15 vkarpov15 left a comment

Choose a reason for hiding this comment

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

Thanks 👍

Copy link
Collaborator

@vkarpov15 vkarpov15 left a comment

Choose a reason for hiding this comment

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

Thanks 👍

@vkarpov15 vkarpov15 added this to the 6.9.1 milestone Feb 4, 2023
@vkarpov15 vkarpov15 merged commit 1fd5d7d into Automattic:master Feb 4, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants