If I explicitly set the type of a PopulatedDoc variable using populate in a query, the virtual variables of the retrieved instances become nonexistent #15111
Labels
confirmed-bug
We've confirmed this is a bug in Mongoose and will fix it.
typescript
Types or Types-test related issue / Pull Request
Milestone
Prerequisites
Mongoose version
8.9.1
Node.js version
20.10.0
MongoDB server version
6.0.2
Typescript version (if applicable)
5.5.4
Description
It seems there is a typing conflict when executing a query using populate and explicitly setting the type of the PopulatedDoc variable. It's likely that the virtual variables are being overwritten.
As you can see from the example, in the query I explicitly declare the type of the PopulatedDoc variable "child". After that, if I try to add one of the retrieved instances to an array of type
ParentInstance
, I get a typing error. The same virtual variables no longer exist, and the linter returns an error.The full error:
ParentInstance
is declared like this:If I remove
& IParentVirtuals
from the declaration, the error disappears.Steps to Reproduce
Reproduction link here.
Expected Behavior
If I explicitly set the type of a PopulatedDoc variable, I should still be able to use the virtual variables of the retrieved instances.
The text was updated successfully, but these errors were encountered: