diff --git a/index.d.ts b/index.d.ts index b11c4ab881f..9ebe8855cb0 100644 --- a/index.d.ts +++ b/index.d.ts @@ -1740,8 +1740,9 @@ declare module 'mongoose' { toObject(options?: ToObjectOptions & { flattenMaps?: boolean }): any; } - // eslint-disable-next-line @typescript-eslint/no-empty-interface - interface ObjectId extends mongodb.ObjectId { } + class ObjectId extends mongodb.ObjectId { + _id: this; + } class Subdocument extends Document { $isSingleNested: true; @@ -2218,12 +2219,14 @@ declare module 'mongoose' { }; type ReadonlyPartial = { - readonly [key in keyof TSchema]?: TSchema[key]; + readonly [key in keyof TSchema]?: TSchema[key]; }; type MatchKeysAndValues = ReadonlyPartial & DotAndArrayNotation; - type Condition = T | QuerySelector; + type AllowRegexpForStrings = T extends string ? T | RegExp : T; + + type Condition = AllowRegexpForStrings | QuerySelector; type _FilterQuery = { [P in keyof T]?: P extends '_id' diff --git a/test/typescript/objectid.ts b/test/typescript/objectid.ts index a7f7d60264e..ef593840c06 100644 --- a/test/typescript/objectid.ts +++ b/test/typescript/objectid.ts @@ -4,4 +4,4 @@ const oid = new Types.ObjectId(); oid.toHexString(); oid._id; -Types.ObjectId().toHexString(); \ No newline at end of file +(new Types.ObjectId()).toHexString(); \ No newline at end of file