-
-
Notifications
You must be signed in to change notification settings - Fork 3.8k
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
Lean query results lose populated types #11532
Comments
I got the same problem with the upgrade from 6.2.5 to 6.2.6. |
Downgrading to v6.2.5 does not solve the problem. Additionally, it breaks the first example too. async function main() {
const result = await parent.findOne().populate<{ child: IChild }>('child');
console.log(result.child.name);
/**
Property 'child' does not exist on type '(Omit<unknown, "child"> & { child: IChild; })[] | (Omit<any, "child"> & { child: IChild; })'.
Property 'child' does not exist on type '(Omit<unknown, "child"> & { child: IChild; })[]'.(2339)
*/
const leanResult = await parent
.findOne()
.populate<{ child: IChild }>('child')
.lean();
console.log(leanResult.child.name);
/**
Property 'child' does not exist on type '(Omit<any, "child"> & { child: IChild; }) | (IParent & { _id: ObjectId; })[]'.
Property 'child' does not exist on type '(IParent & { _id: ObjectId; })[]'.(2339)
*/
} Live demo: https://stackblitz.com/edit/ts-node-fmtkmp?file=index.ts |
Should be fixed now. If the bug still exists after you updated mongoose, then feel free to reopen an issue. |
Do you want to request a feature or report a bug?
Bug
What is the current behavior?
Lean query results lose populated types.
If the current behavior is a bug, please provide the steps to reproduce.
Live demo: https://stackblitz.com/edit/ts-node-8yfhy1?file=index.ts
What is the expected behavior?
The lean document's type should be
IParent & {child: IChild}
or something similar, to allow access to the child's properties.What are the versions of Node.js, Mongoose and MongoDB you are using? Note that "latest" is not a version.
node v14.19.0
mongoose v6.2.6
mongodb v4.3.1
The text was updated successfully, but these errors were encountered: