Skip to content

Commit

Permalink
fix(index.d.ts): support implicit $in in FilterQuery
Browse files Browse the repository at this point in the history
Fix #10826
  • Loading branch information
vkarpov15 committed Oct 18, 2021
1 parent 8337f1d commit 8865bd5
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 3 deletions.
6 changes: 3 additions & 3 deletions index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2555,10 +2555,10 @@ declare module 'mongoose' {

type MatchKeysAndValues<TSchema> = ReadonlyPartial<TSchema> & AnyObject;

type ApplyBasicQueryCasting<T> = T extends mongodb.ObjectId ? T | string : // Allow strings for ObjectIds
T extends string ? T | RegExp : // Allow RegExps for strings
type ApplyBasicQueryCasting<T> = T extends mongodb.ObjectId ? T | string | AnyArray<T | string | Document> : // Allow strings for ObjectIds
T extends string ? T | RegExp | AnyArray<T> : // Allow RegExps for strings
T extends (infer U)[] ? T | U : // Allow single array elements for arrays
T;
T | AnyArray<T>;
type Condition<T> = ApplyBasicQueryCasting<T> | QuerySelector<ApplyBasicQueryCasting<T>>;

type _FilterQuery<T> = {
Expand Down
3 changes: 3 additions & 0 deletions test/typescript/queries.ts
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,9 @@ Test.find({ name: { $in: ['Test'] } }).exec().then((res: Array<ITest>) => consol
Test.find({ tags: 'test' }).exec();
Test.find({ tags: { $in: ['test'] } }).exec();

// Implicit `$in`
Test.find({ name: ['Test1', 'Test2'] }).exec();

Test.find({ name: 'test' }, (err: Error, docs: ITest[]) => {
console.log(!!err, docs[0].age);
});
Expand Down

0 comments on commit 8865bd5

Please sign in to comment.