Skip to content

Commit

Permalink
types(query): add $expr to RootQuerySelector
Browse files Browse the repository at this point in the history
Fix #14841
Re: #14764
  • Loading branch information
vkarpov15 committed Aug 29, 2024
1 parent 69dacc2 commit c52f9e7
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 0 deletions.
6 changes: 6 additions & 0 deletions test/types/queries.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -672,3 +672,9 @@ async function gh14545() {
const myProjection = await M.findOne({}).select<SlimTest>({ prop: 1 }).exec();
expectType<SlimTestDocument | null>(myProjection);
}

function gh14841() {
const filter: FilterQuery<{ owners: string[] }> = {
$expr: { $lt: [{ $size: "$owners" }, 10] },

Check failure on line 678 in test/types/queries.test.ts

View workflow job for this annotation

GitHub Actions / Lint TS-Files

Strings must use singlequote

Check failure on line 678 in test/types/queries.test.ts

View workflow job for this annotation

GitHub Actions / Lint TS-Files

Unexpected trailing comma

Check failure on line 678 in test/types/queries.test.ts

View workflow job for this annotation

GitHub Actions / Lint TS-Files

Strings must use singlequote

Check failure on line 678 in test/types/queries.test.ts

View workflow job for this annotation

GitHub Actions / Lint TS-Files

Unexpected trailing comma
};
}

Check warning on line 680 in test/types/queries.test.ts

View workflow job for this annotation

GitHub Actions / Lint TS-Files

Newline required at end of file but not found

Check warning on line 680 in test/types/queries.test.ts

View workflow job for this annotation

GitHub Actions / Lint TS-Files

Newline required at end of file but not found
1 change: 1 addition & 0 deletions types/query.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,7 @@ declare module 'mongoose' {
$where?: string | Function;
/** @see https://www.mongodb.com/docs/manual/reference/operator/query/comment/#op._S_comment */
$comment?: string;
$expr?: Record<string, any>;
// we could not find a proper TypeScript generic to support nested queries e.g. 'user.friends.name'
// this will mark all unrecognized properties as any (including nested queries) only if
// they include a "." (to avoid generically allowing any unexpected keys)
Expand Down

0 comments on commit c52f9e7

Please sign in to comment.