You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I have searched existing issues to ensure the bug has not already been reported
Mongoose version
8.8.2
Node.js version
20.10.0
MongoDB server version
6.0.2
Typescript version (if applicable)
5.5.4
Description
In my repository, I have installed version 8.6.0 of Mongoose. After updating to the latest version (8.8.2), I encountered new typing errors: the PopulatedDoc variables are typed as full Mongoose objects instead of FlattenMaps when the query is lean.
Below are some screenshots:
This is the type returned in version 8.6.0:
This is the type returned in version 8.8.2:
Furthermore, for both versions of Mongoose, the linter does not give me any errors when I run child.save(), but at runtime, I get the expected error child.save is not a function.
As you can see from the screenshot, child is actually a normal object of type IChild (or FlattenMaps<...>), so it correctly throws an error when trying to execute child.save(). However, the linter should already be flagging this issue.
I expect PopulatedDoc variables to be typed with IChild or FlattenMaps<...> when the query is lean.
Ideally, PopulatedDoc variables should be directly typed with FlattenMaps<...> if the query uses the populate method, and with Types.ObjectId if the query does not use the populate method.
The text was updated successfully, but these errors were encountered:
Prerequisites
Mongoose version
8.8.2
Node.js version
20.10.0
MongoDB server version
6.0.2
Typescript version (if applicable)
5.5.4
Description
In my repository, I have installed version
8.6.0
of Mongoose. After updating to the latest version (8.8.2
), I encountered new typing errors: the PopulatedDoc variables are typed as full Mongoose objects instead of FlattenMaps when the query is lean.Below are some screenshots:
This is the type returned in version 8.6.0:
This is the type returned in version 8.8.2:
Furthermore, for both versions of Mongoose, the linter does not give me any errors when I run
child.save()
, but at runtime, I get the expected errorchild.save is not a function
.As you can see from the screenshot, child is actually a normal object of type
IChild
(orFlattenMaps<...>
), so it correctly throws an error when trying to executechild.save()
. However, the linter should already be flagging this issue.Steps to Reproduce
Reproduction link here
Expected Behavior
I expect
PopulatedDoc
variables to be typed withIChild
orFlattenMaps<...>
when the query is lean.Ideally,
PopulatedDoc
variables should be directly typed withFlattenMaps<...>
if the query uses thepopulate
method, and withTypes.ObjectId
if the query does not use thepopulate
method.The text was updated successfully, but these errors were encountered: