-
-
Notifications
You must be signed in to change notification settings - Fork 3.9k
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: Populate query return type. #11560
Conversation
478d856
to
470ac4e
Compare
470ac4e
to
f286273
Compare
@@ -1774,8 +1774,8 @@ declare module 'mongoose' { | |||
polygon(path: string, ...coordinatePairs: number[][]): this; | |||
|
|||
/** Specifies paths which should be populated with other documents. */ | |||
populate<Paths = {}>(path: string | string[], select?: string | any, model?: string | Model<any, THelpers>, match?: any): QueryWithHelpers<UnpackedIntersection<ResultType, Paths>, DocType, THelpers, RawDocType>; | |||
populate<Paths = {}>(options: PopulateOptions | (PopulateOptions | string)[]): QueryWithHelpers<UnpackedIntersection<ResultType, Paths>, DocType, THelpers, RawDocType>; | |||
populate<Paths = {}, TRawDocType = UnpackedIntersection<ResultType, Paths>>(path: string | string[], select?: string | any, model?: string | Model<any, THelpers>, match?: any): QueryWithHelpers<TRawDocType, DocType, THelpers, TRawDocType>; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The ResultType
& RawDocType
type arguments are different. The ResultType
is like a mongoose object, while the RawDocType
is a POJO of your schema.
So the lean
method uses the RawDocType
to correctly specify the return type, so you shouldn't use the UnpackedIntersection<ResultType, Paths>
for both arguments to the QueryWithHelpers
generic type.
So the only replacement should be the RawDocType
argument to the QueryWitHelpers
with UnpackedIntersection<RawDocType, Paths>
, for both overloads.
I just had this issue and wanted to open a PR before seeing yours, hopefully they'll merge it now.
populate<Paths = {}, TRawDocType = UnpackedIntersection<ResultType, Paths>>(path: string | string[], select?: string | any, model?: string | Model<any, THelpers>, match?: any): QueryWithHelpers<TRawDocType, DocType, THelpers, TRawDocType>; | |
populate<Paths = {}>(path: string | string[], select?: string | any, model?: string | Model<any, THelpers>, match?: any): QueryWithHelpers<UnpackedIntersection<ResultType, Paths>, DocType, THelpers, UnpackedIntersection<RawDocType, Paths>>; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I thought I had submitted this review 2 days ago when I got this issue as well 🤦♂️. It's my first review and I didn't know I had to submit the review after starting it again.
Am I wrong to think it's better to use the RawDocType
in the UnpackedIntersection for the 4th argument? Because using the ResultType
, you get the properties of a Mongoose Document. @vkarpov15
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for your comment @iammola, You are correct, and sorry for this mistake.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's all good man. Thanks for the PR!!
Regarding #11532 #11518 #11585