From cf4f851489a4f741f77b1469f6eef2f143102f79 Mon Sep 17 00:00:00 2001 From: FaizBShah Date: Mon, 26 Feb 2024 19:12:31 +0530 Subject: [PATCH 1/2] fix: missing typescript details on options params of updateMany, updateOne, etc. --- types/models.d.ts | 10 +++++----- types/utility.d.ts | 11 +++++++++++ 2 files changed, 16 insertions(+), 5 deletions(-) diff --git a/types/models.d.ts b/types/models.d.ts index a77aa25525e..b232620e1f9 100644 --- a/types/models.d.ts +++ b/types/models.d.ts @@ -228,7 +228,7 @@ declare module 'mongoose' { /** Creates a `countDocuments` query: counts the number of documents that match `filter`. */ countDocuments( filter?: FilterQuery, - options?: (mongodb.CountOptions & Omit, 'lean' | 'timestamps'>) | null + options?: (mongodb.CountOptions & ExcludeKeys, 'lean' | 'timestamps'>) | null ): QueryWithHelpers< number, THydratedDocumentType, @@ -266,7 +266,7 @@ declare module 'mongoose' { */ deleteMany( filter?: FilterQuery, - options?: (mongodb.DeleteOptions & Omit, 'lean' | 'timestamps'>) | null + options?: (mongodb.DeleteOptions & ExcludeKeys, 'lean' | 'timestamps'>) | null ): QueryWithHelpers< mongodb.DeleteResult, THydratedDocumentType, @@ -291,7 +291,7 @@ declare module 'mongoose' { */ deleteOne( filter?: FilterQuery, - options?: (mongodb.DeleteOptions & Omit, 'lean' | 'timestamps'>) | null + options?: (mongodb.DeleteOptions & ExcludeKeys, 'lean' | 'timestamps'>) | null ): QueryWithHelpers< mongodb.DeleteResult, THydratedDocumentType, @@ -743,14 +743,14 @@ declare module 'mongoose' { updateMany( filter?: FilterQuery, update?: UpdateQuery | UpdateWithAggregationPipeline, - options?: (mongodb.UpdateOptions & Omit, 'lean'>) | null + options?: (mongodb.UpdateOptions & ExcludeKeys, 'lean'>) | null ): QueryWithHelpers; /** Creates a `updateOne` query: updates the first document that matches `filter` with `update`. */ updateOne( filter?: FilterQuery, update?: UpdateQuery | UpdateWithAggregationPipeline, - options?: (mongodb.UpdateOptions & Omit, 'lean'>) | null + options?: (mongodb.UpdateOptions & ExcludeKeys, 'lean'>) | null ): QueryWithHelpers; /** Creates a Query, applies the passed conditions, and returns the Query. */ diff --git a/types/utility.d.ts b/types/utility.d.ts index 60005c2e8b7..016f2c48b07 100644 --- a/types/utility.d.ts +++ b/types/utility.d.ts @@ -2,6 +2,17 @@ declare module 'mongoose' { type IfAny = 0 extends (1 & IFTYPE) ? THENTYPE : ELSETYPE; type IfUnknown = unknown extends IFTYPE ? THENTYPE : IFTYPE; + /** + * @summary Removes keys from a type + * @description It helps to exclude keys from a type + * @param {T} T A generic type to be checked. + * @param {K} K Keys from T that are to be excluded from the generic type + * @returns T with the keys in K excluded + */ + type ExcludeKeys = { + [P in keyof T as P extends K ? never : P]: T[P]; + }; + type Unpacked = T extends (infer U)[] ? U : T extends ReadonlyArray ? U : T; From a7f108599b3e356da40a641aa0b0444473ae4798 Mon Sep 17 00:00:00 2001 From: Valeri Karpov Date: Mon, 26 Feb 2024 16:01:33 -0500 Subject: [PATCH 2/2] Update models.d.ts --- types/models.d.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/types/models.d.ts b/types/models.d.ts index 5ac31d24d2a..2a1b73aa05a 100644 --- a/types/models.d.ts +++ b/types/models.d.ts @@ -291,7 +291,7 @@ declare module 'mongoose' { */ deleteOne( filter?: FilterQuery, - options?: (mongodb.DeleteOptions & ExcludeKeys, 'lean' | 'timestamps'>) | null + options?: (mongodb.DeleteOptions & MongooseBaseQueryOptions) | null ): QueryWithHelpers< mongodb.DeleteResult, THydratedDocumentType,