mirror of
https://github.com/gosticks/DefinitelyTyped.git
synced 2026-08-13 13:30:28 +00:00
[mongoose]: allow numbers to be typed corrently when used as _id (#43760)
Co-authored-by: Jonathan Burke <jonathan.burke@codecentric.de>
This commit is contained in:
co-authored by
Jonathan Burke
parent
0448b7d88e
commit
1478539f98
Vendored
+9
-6
@@ -98,12 +98,15 @@ declare module "mongoose" {
|
||||
* which would result in a passing conditional, because `never` is included in all types.
|
||||
*/
|
||||
export type MongooseFilterQuery<T> = {
|
||||
[P in keyof T]?: P extends '_id' ?
|
||||
mongodb.Condition<string | mongodb.ObjectId | { _id: mongodb.ObjectId }> :
|
||||
[Extract<T[P], mongodb.ObjectId>] extends [never] ?
|
||||
mongodb.Condition<T[P]> :
|
||||
mongodb.Condition<T[P] | string>;
|
||||
} & mongodb.RootQuerySelector<T>;
|
||||
[P in keyof T]?: P extends '_id'
|
||||
? [Extract<T[P], mongodb.ObjectId>] extends [never]
|
||||
? mongodb.Condition<T[P]>
|
||||
: mongodb.Condition<T[P] | string | { _id: mongodb.ObjectId }>
|
||||
: [Extract<T[P], mongodb.ObjectId>] extends [never]
|
||||
? mongodb.Condition<T[P]>
|
||||
: mongodb.Condition<T[P] | string>;
|
||||
} &
|
||||
mongodb.RootQuerySelector<T>;
|
||||
|
||||
/* FilterQuery alias type for using as type for filter/conditions parameters */
|
||||
export type FilterQuery<T> = MongooseFilterQuery<DocumentDefinition<T>>;
|
||||
|
||||
@@ -2447,3 +2447,21 @@ Animal2.find().distinct('_id').byName('fido').exec(function(err, animal) {
|
||||
Animal2.findOne().where({ type: 'dog' }).byName('fido').exec(function(err, animal) {
|
||||
console.log(animal);
|
||||
});
|
||||
|
||||
|
||||
/* Filter query */
|
||||
|
||||
interface Foobar extends mongoose.Document {
|
||||
_id: number;
|
||||
name: string;
|
||||
type: string;
|
||||
tags: string[];
|
||||
}
|
||||
var foobarSchema = new mongoose.Schema({
|
||||
_id: Number,
|
||||
name: String,
|
||||
type: String,
|
||||
tags: { type: [String], index: true } // field level
|
||||
});
|
||||
var Foobar = mongoose.model<Foobar, mongoose.Model<Foobar>>('AnimFoobarl', foobarSchema);
|
||||
Foobar.find({ _id: 123 });
|
||||
|
||||
Reference in New Issue
Block a user