Skip to content

Commit

Permalink
Merge pull request #11885 from ghost91-/make-sort-arg-optional
Browse files Browse the repository at this point in the history
make arg of Query.sort optional in the type definitions
  • Loading branch information
Uzlopak committed Jun 2, 2022
2 parents 6cdbd89 + abd3f3e commit ebab664
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 1 deletion.
9 changes: 9 additions & 0 deletions test/types/queries.test.ts
Expand Up @@ -137,6 +137,15 @@ const p1: Record<string, number> = Test.find().projection('age docs.id');
const p2: Record<string, number> | null = Test.find().projection();
const p3: null = Test.find().projection(null);

// Sorting
Test.find().sort();
Test.find().sort('-name');
Test.find().sort({ name: -1 });
Test.find().sort({ name: 'ascending' });
Test.find().sort(undefined);
Test.find().sort(null);
expectError(Test.find().sort({ name: 2 }));
expectError(Test.find().sort({ name: 'invalidSortOrder' }));

// Super generic query
function testGenericQuery(): void {
Expand Down
2 changes: 1 addition & 1 deletion types/query.d.ts
Expand Up @@ -579,7 +579,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 }): this;
sort(arg?: string | { [key: string]: SortOrder } | undefined | null): this;

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

0 comments on commit ebab664

Please sign in to comment.