Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
test: add some docs
  • Loading branch information
vkarpov15 committed May 13, 2025
commit e109cab746979f503d28cdf0456f49f1677c869d
9 changes: 9 additions & 0 deletions test/types/queries.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -678,3 +678,12 @@
$expr: { $lt: [{ $size: '$owners' }, 10] }
};
}

function gh14510() {
// From https://stackoverflow.com/questions/56505560/how-to-fix-ts2322-could-be-instantiated-with-a-different-subtype-of-constraint:
// "Never assign a concrete type to a generic type parameter, consider it as read-only!"
// This function is generally something you shouldn't do in TypeScript, can work around it with `as` though.
function findById<ModelType extends {_id: Types.ObjectId | string}>(model: Model<ModelType>, _id: Types.ObjectId | string) {
return model.find({_id: _id} as FilterQuery<ModelType>);

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

View workflow job for this annotation

GitHub Actions / Lint TS-Files

A space is required after '{'

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

View workflow job for this annotation

GitHub Actions / Lint TS-Files

A space is required before '}'

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

View workflow job for this annotation

GitHub Actions / Lint TS-Files

A space is required after '{'

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

View workflow job for this annotation

GitHub Actions / Lint TS-Files

A space is required before '}'
}
}
2 changes: 1 addition & 1 deletion types/query.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ declare module 'mongoose' {
* { age: { $gte: 30 } }
* ```
*/
type RootFilterQuery<T> = FilterQuery<T> | Query<any, any> | Types.ObjectId;
type RootFilterQuery<T> = FilterQuery<T>;

type FilterQuery<T> = { [P in keyof T]?: Condition<T[P]>; } & RootQuerySelector<T>;

Expand Down
Loading