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: Fixes and improves Query.projection method signature #11210

Merged
merged 4 commits into from
Jan 20, 2022

Conversation

EugeneKorshenko
Copy link
Contributor

Summary

Fixes type mismatch introduced here #11176
Auto completion for Query.projection method should be more efficient and also allows dot notation for nested fields, etc.

@EugeneKorshenko
Copy link
Contributor Author

@vkarpov15 please, take a quick look once you have a chance 🙂

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.

The general idea looks good. I double checked the performance against #10349 and it doesn't look like this causes any major performance issues. Only thing to fix up is removing the restriction that RHS of projection properties should be numbers, that isn't entirely correct.

index.d.ts Outdated
@@ -2117,6 +2117,8 @@ declare module 'mongoose' {

type UnpackedIntersection<T, U> = T extends (infer V)[] ? (V & U)[] : T & U;

type ProjectionFields<DocType> = {[Key in keyof Omit<LeanDocument<DocType>, '__v'>]?: number} & Record<string, number>;
Copy link
Collaborator

Choose a reason for hiding this comment

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

I don't like restricting projections to numbers. There are plenty of codebases out there that use true/false instead of 0/1. And MongoDB does also allow using strings in select(), although that has different behavior than using true/false or 0/1.

Ideally I'd say this should be [Key in keyof Omit<LeanDocument<DocType>, '__v'>]?: any, but if you want to be more strict than that, we need to support:

  1. Boolean
  2. String
  3. Projection operators

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thank you for your review. I'll follow your version with any.

@vkarpov15 vkarpov15 changed the base branch from master to 6.2 January 20, 2022 02:04
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.

Merging this into 6.2 branch, thanks 👍

@vkarpov15 vkarpov15 added this to the 6.2.0 milestone Jan 20, 2022
@vkarpov15 vkarpov15 merged commit d6898a7 into Automattic:6.2 Jan 20, 2022
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.

2 participants