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

add type def for Aggreaget#model without arguments #12864

Conversation

dmshvetsov
Copy link
Contributor

@dmshvetsov dmshvetsov commented Jan 3, 2023

Summary

add missing type definition for Aggregate.prototype.model function that can be used for set or get Model from an Aggregate object.

According to mongoose documentation Aggregate.prototype.model can be used in two ways:

      const aggregate = MyModel.aggregate([{ $match: { answer: 42 } }]);
      aggregate.model() === MyModel; // true
 
      // Change the model. There's rarely any reason to do this.
      aggregate.model(SomeOtherModel);
      aggregate.model() === SomeOtherModel; // true

...to get the aggregation object model and to set it.

But types/aggregate.d.ts is missing type definition for the get case of Aggregate.prototype.model function

This PR aims to fix this.

Examples

Copy link
Collaborator

@AbdelrahmanHafez AbdelrahmanHafez left a comment

Choose a reason for hiding this comment

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

Welcome @dmshvetsov 👋

Can you please add a test to test/types to prevent future regressions?

Thanks!

@dmshvetsov
Copy link
Contributor Author

Welcome @dmshvetsov 👋

Can you please add a test to test/types to prevent future regressions?

Thanks!

sure, will do

@dmshvetsov
Copy link
Contributor Author

@AbdelrahmanHafez could you take another look? I've added type tests for Aggregate.prototype.model

Copy link
Collaborator

@AbdelrahmanHafez AbdelrahmanHafez left a comment

Choose a reason for hiding this comment

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

LGTM, thanks! 👍

@AbdelrahmanHafez AbdelrahmanHafez added the typescript Types or Types-test related issue / Pull Request label Jan 4, 2023
@AbdelrahmanHafez AbdelrahmanHafez added this to the 6.8.3 milestone Jan 4, 2023
@AbdelrahmanHafez AbdelrahmanHafez merged commit e9b5eed into Automattic:master Jan 4, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
typescript Types or Types-test related issue / Pull Request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants