-
-
Notifications
You must be signed in to change notification settings - Fork 3.9k
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
fix(typescript): aggregate.sort()
accepts a string but also { field: 'asc'|'ascending'|'desc'|'descending' }
#11479
fix(typescript): aggregate.sort()
accepts a string but also { field: 'asc'|'ascending'|'desc'|'descending' }
#11479
Conversation
Fix `Argument of type 'string' is not assignable to parameter of type 'Record<string, 1 | -1 | { $meta: "textScore"; }>'` when calling `model.aggregate().sort("-name")`. According to the current implementation (and per the mongoose docs), `aggregate().sort()` also accepts a string.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please add a test case verifying the type under test/typescript to avoid this being changed some time in the future.
Other than the test case, LGTM. |
+1000, I thought there was no test for types (I expected to find them under Since there was no test for |
aggregate.sort()
also accepts a string aggregate.sort()
also accepts a string but also { field: 'asc'|'ascending'|'desc'|'descending' }
aggregate.sort()
also accepts a string but also { field: 'asc'|'ascending'|'desc'|'descending' }
aggregate.sort()
accepts a string but also { field: 'asc'|'ascending'|'desc'|'descending' }
Yeah, it is nice to see the typings tests |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM, Thanks 👍
When using TypeScript, calling
model.aggregate().sort("-name")
generates the following error:This PR also adds support for mongoose sort keywords:
asc
,ascending
,desc
anddescending
(according to the current implementation and the mongoose docs).