Skip to content

Commit

Permalink
fix(types): add "array of key-value pairs" as a argument option for "…
Browse files Browse the repository at this point in the history
…query.sort()"

fixes #12434
  • Loading branch information
hasezoey committed Sep 29, 2022
1 parent 3e55650 commit e00a43a
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 1 deletion.
5 changes: 5 additions & 0 deletions test/types/queries.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -160,8 +160,13 @@ Test.find().sort({ name: -1 });
Test.find().sort({ name: 'ascending' });
Test.find().sort(undefined);
Test.find().sort(null);
Test.find().sort([['key', 'ascending']]);
Test.find().sort([['key1', 'ascending'], ['key2', 'descending']]);
expectError(Test.find().sort({ name: 2 }));
expectError(Test.find().sort({ name: 'invalidSortOrder' }));
expectError(Test.find().sort([['key', 'invalid']]));
expectError(Test.find().sort([['key', false]]));
expectError(Test.find().sort(['invalid']));

// Super generic query
function testGenericQuery(): void {
Expand Down
2 changes: 1 addition & 1 deletion types/query.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -601,7 +601,7 @@ declare module 'mongoose' {
snapshot(val?: boolean): this;

/** Sets the sort order. If an object is passed, values allowed are `asc`, `desc`, `ascending`, `descending`, `1`, and `-1`. */
sort(arg?: string | { [key: string]: SortOrder | { $meta: 'textScore' } } | undefined | null): this;
sort(arg?: string | { [key: string]: SortOrder | { $meta: 'textScore' } } | [[string, SortOrder]] | undefined | null): this;

/** Sets the tailable option (for use with capped collections). */
tailable(bool?: boolean, opts?: {
Expand Down

0 comments on commit e00a43a

Please sign in to comment.