From baf3938b928a42a5dedee6e939d5701d06014a28 Mon Sep 17 00:00:00 2001 From: Valeri Karpov Date: Tue, 2 Feb 2021 10:55:14 -0500 Subject: [PATCH] chore: clean up some inconsistencies with mongodbs new TS types --- index.d.ts | 11 +++++++---- test/typescript/objectid.ts | 2 +- 2 files changed, 8 insertions(+), 5 deletions(-) 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