From 1478539f981601c0cc2e75df22eba26dd755d8eb Mon Sep 17 00:00:00 2001 From: Jonathan Burke Date: Thu, 9 Apr 2020 22:17:20 +0200 Subject: [PATCH] [mongoose]: allow numbers to be typed corrently when used as _id (#43760) Co-authored-by: Jonathan Burke --- types/mongoose/index.d.ts | 15 +++++++++------ types/mongoose/mongoose-tests.ts | 18 ++++++++++++++++++ 2 files changed, 27 insertions(+), 6 deletions(-) diff --git a/types/mongoose/index.d.ts b/types/mongoose/index.d.ts index e19b646ba8..1bbda635a5 100644 --- a/types/mongoose/index.d.ts +++ b/types/mongoose/index.d.ts @@ -98,12 +98,15 @@ declare module "mongoose" { * which would result in a passing conditional, because `never` is included in all types. */ export type MongooseFilterQuery = { - [P in keyof T]?: P extends '_id' ? - mongodb.Condition : - [Extract] extends [never] ? - mongodb.Condition : - mongodb.Condition; - } & mongodb.RootQuerySelector; + [P in keyof T]?: P extends '_id' + ? [Extract] extends [never] + ? mongodb.Condition + : mongodb.Condition + : [Extract] extends [never] + ? mongodb.Condition + : mongodb.Condition; + } & + mongodb.RootQuerySelector; /* FilterQuery alias type for using as type for filter/conditions parameters */ export type FilterQuery = MongooseFilterQuery>; diff --git a/types/mongoose/mongoose-tests.ts b/types/mongoose/mongoose-tests.ts index 548d63e930..869de40c7f 100644 --- a/types/mongoose/mongoose-tests.ts +++ b/types/mongoose/mongoose-tests.ts @@ -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>('AnimFoobarl', foobarSchema); +Foobar.find({ _id: 123 });