-
-
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
(Typescript) toObject on populated documents loses the structure #14441
Labels
typescript
Types or Types-test related issue / Pull Request
Milestone
Comments
vkarpov15
added a commit
that referenced
this issue
Apr 15, 2024
vkarpov15
added a commit
that referenced
this issue
Apr 24, 2024
types(query+populate): apply populate overrides to doc `toObject()` result
@vkarpov15 Thank you - looking forward to give it a try! |
This was referenced May 21, 2024
This was referenced May 21, 2024
Merged
This was referenced Jun 7, 2024
This was referenced Jun 9, 2024
This was referenced Jun 12, 2024
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Prerequisites
Mongoose version
8.2.2
Node.js version
20
MongoDB server version
5.x
Typescript version (if applicable)
5.2.2
Description
When calling toObject on a populated document (which used a type parameter in
populate
) the type structure is lost.Steps to Reproduce
Based on the example from the docs:
Expected Behavior
I'd expect that the passed type information (ie.
{ child: Child }
) is preserved when callingtoObject
.Not sure if this can be done, so let me add a question: Are there any recommendations for a workaround? We do quite some heavy population in different combinations and I'd ideally like to infer the typings based on the already existing types.
Something like this works, but is quite tedious:
The text was updated successfully, but these errors were encountered: