I'm building a query with population, and in the result I want to check whether the document is populated or not, but I'm doing the query with lean() so I can return stringified documents.
Perhaps weird, but the usage looks sort of like this:
await someModel.find({}).populate({path: 'someOtherModel', match: {field: searchQuery})
.lean.exec().then((result: <LeanDocument<someModelType>>[]))=>{
let ret = new Array<LeanDocument<someModelType>>();
result.forEach(document=>{
if (document.populated('someOtherModel')) {
//error above: Property 'populated' does not exist on type <LeanDocument<someModelType>>
ret.push(document);
}
...
}
res.send(JSON.stringify(ret));
});
I don't think the particular use case should matter, but the reason for this populated() check is because in this query (not shown here) I'm sending documents that didn't populate successfully but do match some other search query.
So, is there anything I could do to make typescript not scream at me with that populated() check (aside from putting a populated field in a custom type)?