Skip to content
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

type(query): changed return type of lean() to include null #13155

Merged
merged 6 commits into from Mar 22, 2023

Conversation

lpizzinidev
Copy link
Contributor

Summary
The lean() method return type has been changed to QueryWithHelpers<LeanResultType | null, DocType, THelpers, RawDocType>.

Closes #13151

test/types/lean.test.ts Outdated Show resolved Hide resolved
test/types/lean.test.ts Outdated Show resolved Hide resolved
types/query.d.ts Outdated
@@ -430,7 +430,7 @@ declare module 'mongoose' {
j(val: boolean | null): this;

/** Sets the lean option. */
lean<LeanResultType = ResultType extends any[] ? Require_id<RawDocType>[] : Require_id<RawDocType>>(val?: boolean | any): QueryWithHelpers<LeanResultType, DocType, THelpers, RawDocType>;
lean<LeanResultType = ResultType extends any[] ? Require_id<RawDocType>[] : Require_id<RawDocType>>(val?: boolean | any): QueryWithHelpers<LeanResultType | null, DocType, THelpers, RawDocType>;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Probably need an extra condition here to only add null if ResultType is nullable. That should work around the orFail() issue.

types/query.d.ts Outdated Show resolved Hide resolved
Copy link
Collaborator

@vkarpov15 vkarpov15 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks 👍

@vkarpov15 vkarpov15 added this to the 7.0.3 milestone Mar 22, 2023
@vkarpov15 vkarpov15 merged commit f42df47 into Automattic:master Mar 22, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

typescript Model#findOne() return type is not as expected
3 participants