From dcd3435addf312cf420d9aeee6dc20a71ef8818b Mon Sep 17 00:00:00 2001 From: Valeri Karpov Date: Thu, 26 Dec 2024 15:57:06 -0500 Subject: [PATCH 1/3] types(model+query): avoid stripping out virtuals when calling populate with paths generic Fix #15111 --- test/types/populate.test.ts | 99 ++++++++++++++++++++++++++++++++++++- types/models.d.ts | 94 +++++++++++++++++------------------ types/query.d.ts | 98 ++++++++++++++++++------------------ 3 files changed, 194 insertions(+), 97 deletions(-) diff --git a/test/types/populate.test.ts b/test/types/populate.test.ts index 9829fa8279..792971ed6c 100644 --- a/test/types/populate.test.ts +++ b/test/types/populate.test.ts @@ -1,4 +1,4 @@ -import mongoose, { Schema, model, Document, PopulatedDoc, Types, HydratedDocument, SchemaTypeOptions } from 'mongoose'; +import mongoose, { Schema, model, Document, PopulatedDoc, Types, HydratedDocument, SchemaTypeOptions, Model } from 'mongoose'; // Use the mongodb ObjectId to make instanceof calls possible import { ObjectId } from 'mongodb'; import { expectAssignable, expectError, expectType } from 'tsd'; @@ -459,3 +459,100 @@ async function gh14574() { expectType(user.fullName()); expectType(user.friend.fullName()); } + +async function gh15111() { + interface IChild { + _id: Types.ObjectId; + name: string; + } + + type ChildDocumentOverrides = {}; + + interface IChildVirtuals { + id: string; + } + + type ChildInstance = HydratedDocument< + IChild, + ChildDocumentOverrides & IChildVirtuals + >; + + type ChildModelType = Model< + IChild, + {}, + ChildDocumentOverrides, + IChildVirtuals, + ChildInstance + >; + const childSchema = new Schema( + { + name: { + type: 'String', + required: true, + trim: true + } + }, + { + optimisticConcurrency: true + } + ); + const ChildModel = mongoose.model('Child', childSchema); + + interface IParent { + _id: Types.ObjectId; + name: string; + surname: string; + child: PopulatedDoc & IChild>; + } + + type ParentDocumentOverrides = {}; + + interface IParentVirtuals { + id: string; + fullName: string; + } + + type ParentInstance = HydratedDocument< + IParent, + ParentDocumentOverrides & IParentVirtuals + >; + + type ParentModelType = Model< + IParent, + {}, + ParentDocumentOverrides, + IParentVirtuals, + ParentInstance + >; + const parentSchema = new Schema( + { + name: { + type: 'String', + required: true, + trim: true + }, + surname: { + type: 'String', + required: true, + trim: true + }, + child: { + type: 'ObjectId', + ref: 'Child', + required: true + } + }, + { optimisticConcurrency: true } + ); + + parentSchema.virtual('fullName').get(function() { + return `${this.name} ${this.surname}`; + }); + + const ParentModel = mongoose.model('Parent', parentSchema); + + const parents = await ParentModel.find().populate<{ child: ChildInstance }>( + 'child' + ); + expectType(parents[0].fullName); +} diff --git a/types/models.d.ts b/types/models.d.ts index 5a5ced6094..99028762f2 100644 --- a/types/models.d.ts +++ b/types/models.d.ts @@ -333,7 +333,7 @@ declare module 'mongoose' { TQueryHelpers, TRawDocType, 'countDocuments', - TInstanceMethods + TInstanceMethods & TVirtuals >; /** Creates a new document or documents */ @@ -372,7 +372,7 @@ declare module 'mongoose' { TQueryHelpers, TRawDocType, 'deleteMany', - TInstanceMethods + TInstanceMethods & TVirtuals >; deleteMany( filter: RootFilterQuery @@ -382,7 +382,7 @@ declare module 'mongoose' { TQueryHelpers, TRawDocType, 'deleteMany', - TInstanceMethods + TInstanceMethods & TVirtuals >; /** @@ -399,7 +399,7 @@ declare module 'mongoose' { TQueryHelpers, TRawDocType, 'deleteOne', - TInstanceMethods + TInstanceMethods & TVirtuals >; deleteOne( filter: RootFilterQuery @@ -409,7 +409,7 @@ declare module 'mongoose' { TQueryHelpers, TRawDocType, 'deleteOne', - TInstanceMethods + TInstanceMethods & TVirtuals >; /** @@ -439,17 +439,17 @@ declare module 'mongoose' { TQueryHelpers, TRawDocType, 'findOne', - TInstanceMethods + TInstanceMethods & TVirtuals >; findById( id: any, projection?: ProjectionType | null, options?: QueryOptions | null - ): QueryWithHelpers; + ): QueryWithHelpers; findById( id: any, projection?: ProjectionType | null - ): QueryWithHelpers; + ): QueryWithHelpers; /** Finds one document. */ findOne( @@ -462,20 +462,20 @@ declare module 'mongoose' { TQueryHelpers, TRawDocType, 'findOne', - TInstanceMethods + TInstanceMethods & TVirtuals >; findOne( filter?: RootFilterQuery, projection?: ProjectionType | null, options?: QueryOptions | null - ): QueryWithHelpers; + ): QueryWithHelpers; findOne( filter?: RootFilterQuery, projection?: ProjectionType | null - ): QueryWithHelpers; + ): QueryWithHelpers; findOne( filter?: RootFilterQuery - ): QueryWithHelpers; + ): QueryWithHelpers; /** * Shortcut for creating a new Document from existing raw data, pre-saved in the DB. @@ -617,7 +617,7 @@ declare module 'mongoose' { watch(pipeline?: Array>, options?: mongodb.ChangeStreamOptions & { hydrate?: boolean }): mongodb.ChangeStream; /** Adds a `$where` clause to this query */ - $where(argument: string | Function): QueryWithHelpers, THydratedDocumentType, TQueryHelpers, TRawDocType, 'find', TInstanceMethods>; + $where(argument: string | Function): QueryWithHelpers, THydratedDocumentType, TQueryHelpers, TRawDocType, 'find', TInstanceMethods & TVirtuals>; /** Registered discriminators for this model. */ discriminators: { [name: string]: Model } | undefined; @@ -640,7 +640,7 @@ declare module 'mongoose' { TQueryHelpers, TRawDocType, 'distinct', - TInstanceMethods + TInstanceMethods & TVirtuals >; /** Creates a `estimatedDocumentCount` query: counts the number of documents in the collection. */ @@ -650,7 +650,7 @@ declare module 'mongoose' { TQueryHelpers, TRawDocType, 'estimatedDocumentCount', - TInstanceMethods + TInstanceMethods & TVirtuals >; /** @@ -665,7 +665,7 @@ declare module 'mongoose' { TQueryHelpers, TRawDocType, 'findOne', - TInstanceMethods + TInstanceMethods & TVirtuals >; /** Creates a `find` query: gets a list of documents that match `filter`. */ @@ -679,22 +679,22 @@ declare module 'mongoose' { TQueryHelpers, TRawDocType, 'find', - TInstanceMethods + TInstanceMethods & TVirtuals >; find( filter: RootFilterQuery, projection?: ProjectionType | null | undefined, options?: QueryOptions | null | undefined - ): QueryWithHelpers, ResultDoc, TQueryHelpers, TRawDocType, 'find', TInstanceMethods>; + ): QueryWithHelpers, ResultDoc, TQueryHelpers, TRawDocType, 'find', TInstanceMethods & TVirtuals>; find( filter: RootFilterQuery, projection?: ProjectionType | null | undefined - ): QueryWithHelpers, ResultDoc, TQueryHelpers, TRawDocType, 'find', TInstanceMethods>; + ): QueryWithHelpers, ResultDoc, TQueryHelpers, TRawDocType, 'find', TInstanceMethods & TVirtuals>; find( filter: RootFilterQuery - ): QueryWithHelpers, ResultDoc, TQueryHelpers, TRawDocType, 'find', TInstanceMethods>; + ): QueryWithHelpers, ResultDoc, TQueryHelpers, TRawDocType, 'find', TInstanceMethods & TVirtuals>; find( - ): QueryWithHelpers, ResultDoc, TQueryHelpers, TRawDocType, 'find', TInstanceMethods>; + ): QueryWithHelpers, ResultDoc, TQueryHelpers, TRawDocType, 'find', TInstanceMethods & TVirtuals>; /** Creates a `findByIdAndDelete` query, filtering by the given `_id`. */ findByIdAndDelete( @@ -706,16 +706,16 @@ declare module 'mongoose' { TQueryHelpers, TRawDocType, 'findOneAndDelete', - TInstanceMethods + TInstanceMethods & TVirtuals >; findByIdAndDelete( id: mongodb.ObjectId | any, options: QueryOptions & { includeResultMetadata: true } - ): QueryWithHelpers, ResultDoc, TQueryHelpers, TRawDocType, 'findOneAndDelete', TInstanceMethods>; + ): QueryWithHelpers, ResultDoc, TQueryHelpers, TRawDocType, 'findOneAndDelete', TInstanceMethods & TVirtuals>; findByIdAndDelete( id?: mongodb.ObjectId | any, options?: QueryOptions | null - ): QueryWithHelpers; + ): QueryWithHelpers; /** Creates a `findOneAndUpdate` query, filtering by the given `_id`. */ findByIdAndUpdate( @@ -728,7 +728,7 @@ declare module 'mongoose' { TQueryHelpers, TRawDocType, 'findOneAndUpdate', - TInstanceMethods + TInstanceMethods & TVirtuals >; findByIdAndUpdate( id: mongodb.ObjectId | any, @@ -740,27 +740,27 @@ declare module 'mongoose' { TQueryHelpers, TRawDocType, 'findOneAndUpdate', - TInstanceMethods + TInstanceMethods & TVirtuals >; findByIdAndUpdate( id: mongodb.ObjectId | any, update: UpdateQuery, options: QueryOptions & { includeResultMetadata: true } - ): QueryWithHelpers, ResultDoc, TQueryHelpers, TRawDocType, 'findOneAndUpdate', TInstanceMethods>; + ): QueryWithHelpers, ResultDoc, TQueryHelpers, TRawDocType, 'findOneAndUpdate', TInstanceMethods & TVirtuals>; findByIdAndUpdate( id: mongodb.ObjectId | any, update: UpdateQuery, options: QueryOptions & { upsert: true } & ReturnsNewDoc - ): QueryWithHelpers; + ): QueryWithHelpers; findByIdAndUpdate( id?: mongodb.ObjectId | any, update?: UpdateQuery, options?: QueryOptions | null - ): QueryWithHelpers; + ): QueryWithHelpers; findByIdAndUpdate( id: mongodb.ObjectId | any, update: UpdateQuery - ): QueryWithHelpers; + ): QueryWithHelpers; /** Creates a `findOneAndDelete` query: atomically finds the given document, deletes it, and returns the document as it was before deletion. */ findOneAndDelete( @@ -772,16 +772,16 @@ declare module 'mongoose' { TQueryHelpers, TRawDocType, 'findOneAndDelete', - TInstanceMethods + TInstanceMethods & TVirtuals >; findOneAndDelete( filter: RootFilterQuery, options: QueryOptions & { includeResultMetadata: true } - ): QueryWithHelpers, ResultDoc, TQueryHelpers, TRawDocType, 'findOneAndDelete', TInstanceMethods>; + ): QueryWithHelpers, ResultDoc, TQueryHelpers, TRawDocType, 'findOneAndDelete', TInstanceMethods & TVirtuals>; findOneAndDelete( filter?: RootFilterQuery | null, options?: QueryOptions | null - ): QueryWithHelpers; + ): QueryWithHelpers; /** Creates a `findOneAndReplace` query: atomically finds the given document and replaces it with `replacement`. */ findOneAndReplace( @@ -794,23 +794,23 @@ declare module 'mongoose' { TQueryHelpers, TRawDocType, 'findOneAndReplace', - TInstanceMethods + TInstanceMethods & TVirtuals >; findOneAndReplace( filter: RootFilterQuery, replacement: TRawDocType | AnyObject, options: QueryOptions & { includeResultMetadata: true } - ): QueryWithHelpers, ResultDoc, TQueryHelpers, TRawDocType, 'findOneAndReplace', TInstanceMethods>; + ): QueryWithHelpers, ResultDoc, TQueryHelpers, TRawDocType, 'findOneAndReplace', TInstanceMethods & TVirtuals>; findOneAndReplace( filter: RootFilterQuery, replacement: TRawDocType | AnyObject, options: QueryOptions & { upsert: true } & ReturnsNewDoc - ): QueryWithHelpers; + ): QueryWithHelpers; findOneAndReplace( filter?: RootFilterQuery, replacement?: TRawDocType | AnyObject, options?: QueryOptions | null - ): QueryWithHelpers; + ): QueryWithHelpers; /** Creates a `findOneAndUpdate` query: atomically find the first document that matches `filter` and apply `update`. */ findOneAndUpdate( @@ -823,7 +823,7 @@ declare module 'mongoose' { TQueryHelpers, TRawDocType, 'findOneAndUpdate', - TInstanceMethods + TInstanceMethods & TVirtuals >; findOneAndUpdate( filter: RootFilterQuery, @@ -835,30 +835,30 @@ declare module 'mongoose' { TQueryHelpers, TRawDocType, 'findOneAndUpdate', - TInstanceMethods + TInstanceMethods & TVirtuals >; findOneAndUpdate( filter: RootFilterQuery, update: UpdateQuery, options: QueryOptions & { includeResultMetadata: true } - ): QueryWithHelpers, ResultDoc, TQueryHelpers, TRawDocType, 'findOneAndUpdate', TInstanceMethods>; + ): QueryWithHelpers, ResultDoc, TQueryHelpers, TRawDocType, 'findOneAndUpdate', TInstanceMethods & TVirtuals>; findOneAndUpdate( filter: RootFilterQuery, update: UpdateQuery, options: QueryOptions & { upsert: true } & ReturnsNewDoc - ): QueryWithHelpers; + ): QueryWithHelpers; findOneAndUpdate( filter?: RootFilterQuery, update?: UpdateQuery, options?: QueryOptions | null - ): QueryWithHelpers; + ): QueryWithHelpers; /** Creates a `replaceOne` query: finds the first document that matches `filter` and replaces it with `replacement`. */ replaceOne( filter?: RootFilterQuery, replacement?: TRawDocType | AnyObject, options?: (mongodb.ReplaceOptions & MongooseQueryOptions) | null - ): QueryWithHelpers; + ): QueryWithHelpers; /** Apply changes made to this model's schema after this model was compiled. */ recompileSchema(): void; @@ -871,14 +871,14 @@ declare module 'mongoose' { filter?: RootFilterQuery, update?: UpdateQuery | UpdateWithAggregationPipeline, options?: (mongodb.UpdateOptions & MongooseUpdateQueryOptions) | null - ): QueryWithHelpers; + ): QueryWithHelpers; /** Creates a `updateOne` query: updates the first document that matches `filter` with `update`. */ updateOne( filter?: RootFilterQuery, update?: UpdateQuery | UpdateWithAggregationPipeline, options?: (mongodb.UpdateOptions & MongooseUpdateQueryOptions) | null - ): QueryWithHelpers; + ): QueryWithHelpers; /** Creates a Query, applies the passed conditions, and returns the Query. */ where( @@ -891,7 +891,7 @@ declare module 'mongoose' { TQueryHelpers, TRawDocType, 'find', - TInstanceMethods + TInstanceMethods & TVirtuals >; where(): QueryWithHelpers< Array, @@ -899,7 +899,7 @@ declare module 'mongoose' { TQueryHelpers, TRawDocType, 'find', - TInstanceMethods + TInstanceMethods & TVirtuals >; } } diff --git a/types/query.d.ts b/types/query.d.ts index b2d4da347b..3fc701a365 100644 --- a/types/query.d.ts +++ b/types/query.d.ts @@ -53,8 +53,8 @@ declare module 'mongoose' { THelpers = {}, RawDocType = DocType, QueryOp = 'find', - TInstanceMethods = Record - > = Query & THelpers; + TDocOverrides = Record + > = Query & THelpers; type QuerySelector = { // Comparison @@ -226,19 +226,19 @@ declare module 'mongoose' { ? (ResultType extends any[] ? Default__v>>>[] : Default__v>>>) : ResultType; - type MergePopulatePaths> = QueryOp extends QueryOpThatReturnsDocument + type MergePopulatePaths> = QueryOp extends QueryOpThatReturnsDocument ? ResultType extends null ? ResultType : ResultType extends (infer U)[] ? U extends Document - ? HydratedDocument, TInstanceMethods, TQueryHelpers>[] + ? HydratedDocument, TDocOverrides, TQueryHelpers>[] : (MergeType)[] : ResultType extends Document - ? HydratedDocument, TInstanceMethods, TQueryHelpers> + ? HydratedDocument, TDocOverrides, TQueryHelpers> : MergeType : MergeType; - class Query> implements SessionOperation { + class Query> implements SessionOperation { _mongooseOptions: MongooseQueryOptions; /** @@ -257,7 +257,7 @@ declare module 'mongoose' { THelpers, RawDocType, QueryOp, - TInstanceMethods + TDocOverrides >; /** Specifies an `$all` query condition. When called with one argument, the most recent path passed to `where()` is used. */ @@ -319,7 +319,7 @@ declare module 'mongoose' { countDocuments( criteria?: RootFilterQuery, options?: QueryOptions - ): QueryWithHelpers; + ): QueryWithHelpers; /** * Returns a wrapper around a [mongodb driver cursor](https://mongodb.github.io/node-mongodb-native/4.9/classes/FindCursor.html). @@ -335,16 +335,16 @@ declare module 'mongoose' { deleteMany( filter?: RootFilterQuery, options?: QueryOptions - ): QueryWithHelpers; + ): QueryWithHelpers; deleteMany(filter: RootFilterQuery): QueryWithHelpers< any, DocType, THelpers, RawDocType, 'deleteMany', - TInstanceMethods + TDocOverrides >; - deleteMany(): QueryWithHelpers; + deleteMany(): QueryWithHelpers; /** * Declare and/or execute this query as a `deleteOne()` operation. Works like @@ -354,16 +354,16 @@ declare module 'mongoose' { deleteOne( filter?: RootFilterQuery, options?: QueryOptions - ): QueryWithHelpers; + ): QueryWithHelpers; deleteOne(filter: RootFilterQuery): QueryWithHelpers< any, DocType, THelpers, RawDocType, 'deleteOne', - TInstanceMethods + TDocOverrides >; - deleteOne(): QueryWithHelpers; + deleteOne(): QueryWithHelpers; /** Creates a `distinct` query: returns the distinct values of the given `field` that match `filter`. */ distinct( @@ -380,7 +380,7 @@ declare module 'mongoose' { THelpers, RawDocType, 'distinct', - TInstanceMethods + TDocOverrides >; /** Specifies a `$elemMatch` query condition. When called with one argument, the most recent path passed to `where()` is used. */ @@ -404,7 +404,7 @@ declare module 'mongoose' { THelpers, RawDocType, 'estimatedDocumentCount', - TInstanceMethods + TDocOverrides >; /** Specifies a `$exists` query condition. When called with one argument, the most recent path passed to `where()` is used. */ @@ -424,29 +424,29 @@ declare module 'mongoose' { filter: RootFilterQuery, projection?: ProjectionType | null, options?: QueryOptions | null - ): QueryWithHelpers, DocType, THelpers, RawDocType, 'find', TInstanceMethods>; + ): QueryWithHelpers, DocType, THelpers, RawDocType, 'find', TDocOverrides>; find( filter: RootFilterQuery, projection?: ProjectionType | null - ): QueryWithHelpers, DocType, THelpers, RawDocType, 'find', TInstanceMethods>; + ): QueryWithHelpers, DocType, THelpers, RawDocType, 'find', TDocOverrides>; find( filter: RootFilterQuery - ): QueryWithHelpers, DocType, THelpers, RawDocType, 'find', TInstanceMethods>; - find(): QueryWithHelpers, DocType, THelpers, RawDocType, 'find', TInstanceMethods>; + ): QueryWithHelpers, DocType, THelpers, RawDocType, 'find', TDocOverrides>; + find(): QueryWithHelpers, DocType, THelpers, RawDocType, 'find', TDocOverrides>; /** Declares the query a findOne operation. When executed, returns the first found document. */ findOne( filter?: RootFilterQuery, projection?: ProjectionType | null, options?: QueryOptions | null - ): QueryWithHelpers; + ): QueryWithHelpers; findOne( filter?: RootFilterQuery, projection?: ProjectionType | null - ): QueryWithHelpers; + ): QueryWithHelpers; findOne( filter?: RootFilterQuery - ): QueryWithHelpers; + ): QueryWithHelpers; /** Creates a `findOneAndDelete` query: atomically finds the given document, deletes it, and returns the document as it was before deletion. */ findOneAndDelete( @@ -459,62 +459,62 @@ declare module 'mongoose' { filter: RootFilterQuery, update: UpdateQuery, options: QueryOptions & { includeResultMetadata: true } - ): QueryWithHelpers, DocType, THelpers, RawDocType, 'findOneAndUpdate', TInstanceMethods>; + ): QueryWithHelpers, DocType, THelpers, RawDocType, 'findOneAndUpdate', TDocOverrides>; findOneAndUpdate( filter: RootFilterQuery, update: UpdateQuery, options: QueryOptions & { upsert: true } & ReturnsNewDoc - ): QueryWithHelpers; + ): QueryWithHelpers; findOneAndUpdate( filter?: RootFilterQuery, update?: UpdateQuery, options?: QueryOptions | null - ): QueryWithHelpers; + ): QueryWithHelpers; /** Declares the query a findById operation. When executed, returns the document with the given `_id`. */ findById( id: mongodb.ObjectId | any, projection?: ProjectionType | null, options?: QueryOptions | null - ): QueryWithHelpers; + ): QueryWithHelpers; findById( id: mongodb.ObjectId | any, projection?: ProjectionType | null - ): QueryWithHelpers; + ): QueryWithHelpers; findById( id: mongodb.ObjectId | any - ): QueryWithHelpers; + ): QueryWithHelpers; /** Creates a `findByIdAndDelete` query, filtering by the given `_id`. */ findByIdAndDelete( id: mongodb.ObjectId | any, options: QueryOptions & { includeResultMetadata: true } - ): QueryWithHelpers, DocType, THelpers, RawDocType, 'findOneAndDelete', TInstanceMethods>; + ): QueryWithHelpers, DocType, THelpers, RawDocType, 'findOneAndDelete', TDocOverrides>; findByIdAndDelete( id?: mongodb.ObjectId | any, options?: QueryOptions | null - ): QueryWithHelpers; + ): QueryWithHelpers; /** Creates a `findOneAndUpdate` query, filtering by the given `_id`. */ findByIdAndUpdate( id: mongodb.ObjectId | any, update: UpdateQuery, options: QueryOptions & { includeResultMetadata: true } - ): QueryWithHelpers; + ): QueryWithHelpers; findByIdAndUpdate( id: mongodb.ObjectId | any, update: UpdateQuery, options: QueryOptions & { upsert: true } & ReturnsNewDoc - ): QueryWithHelpers; + ): QueryWithHelpers; findByIdAndUpdate( id?: mongodb.ObjectId | any, update?: UpdateQuery, options?: QueryOptions | null - ): QueryWithHelpers; + ): QueryWithHelpers; findByIdAndUpdate( id: mongodb.ObjectId | any, update: UpdateQuery - ): QueryWithHelpers; + ): QueryWithHelpers; /** Specifies a `$geometry` condition */ geometry(object: { type: string, coordinates: any[] }): this; @@ -573,7 +573,7 @@ declare module 'mongoose' { THelpers, RawDocType, QueryOp, - TInstanceMethods + TDocOverrides >; lean( val?: boolean | any @@ -585,7 +585,7 @@ declare module 'mongoose' { THelpers, RawDocType, QueryOp, - TInstanceMethods + TDocOverrides >; /** Specifies the maximum number of documents the query will return. */ @@ -603,7 +603,7 @@ declare module 'mongoose' { * Runs a function `fn` and treats the return value of `fn` as the new value * for the query to resolve to. */ - transform(fn: (doc: ResultType) => MappedType): QueryWithHelpers; + transform(fn: (doc: ResultType) => MappedType): QueryWithHelpers; /** Specifies an `$maxDistance` query condition. When called with one argument, the most recent path passed to `where()` is used. */ maxDistance(path: string, val: number): this; @@ -655,7 +655,7 @@ declare module 'mongoose' { * This is handy for integrating with async/await, because `orFail()` saves you * an extra `if` statement to check if no document was found. */ - orFail(err?: NativeError | (() => NativeError)): QueryWithHelpers, DocType, THelpers, RawDocType, QueryOp, TInstanceMethods>; + orFail(err?: NativeError | (() => NativeError)): QueryWithHelpers, DocType, THelpers, RawDocType, QueryOp, TDocOverrides>; /** Specifies a `$polygon` condition */ polygon(path: string, ...coordinatePairs: number[][]): this; @@ -673,7 +673,7 @@ declare module 'mongoose' { THelpers, RawDocType, QueryOp, - TInstanceMethods + TDocOverrides >; populate( options: PopulateOptions | (PopulateOptions | string)[] @@ -683,7 +683,7 @@ declare module 'mongoose' { THelpers, RawDocType, QueryOp, - TInstanceMethods + TDocOverrides >; populate( path: string | string[], @@ -691,22 +691,22 @@ declare module 'mongoose' { model?: string | Model, match?: any ): QueryWithHelpers< - MergePopulatePaths, + MergePopulatePaths, DocType, THelpers, UnpackedIntersection, QueryOp, - TInstanceMethods + TDocOverrides >; populate( options: PopulateOptions | (PopulateOptions | string)[] ): QueryWithHelpers< - MergePopulatePaths, + MergePopulatePaths, DocType, THelpers, UnpackedIntersection, QueryOp, - TInstanceMethods + TDocOverrides >; /** Add pre middleware to this query instance. Doesn't affect other queries. */ @@ -739,7 +739,7 @@ declare module 'mongoose' { filter?: RootFilterQuery, replacement?: DocType | AnyObject, options?: QueryOptions | null - ): QueryWithHelpers; + ): QueryWithHelpers; /** * Sets this query's `sanitizeProjection` option. With `sanitizeProjection()`, you can pass potentially untrusted user data to `.select()`. @@ -777,7 +777,7 @@ declare module 'mongoose' { RawDocTypeOverride >, QueryOp, - TInstanceMethods + TDocOverrides >; /** Determines if field selection has been made. */ @@ -853,7 +853,7 @@ declare module 'mongoose' { filter?: RootFilterQuery, update?: UpdateQuery | UpdateWithAggregationPipeline, options?: QueryOptions | null - ): QueryWithHelpers; + ): QueryWithHelpers; /** * Declare and/or execute this query as an updateOne() operation. Same as @@ -863,7 +863,7 @@ declare module 'mongoose' { filter?: RootFilterQuery, update?: UpdateQuery | UpdateWithAggregationPipeline, options?: QueryOptions | null - ): QueryWithHelpers; + ): QueryWithHelpers; /** * Sets the specified number of `mongod` servers, or tag set of `mongod` servers, From b7e1828c1a8f7b0d0e6e6ab53b58f75a62306849 Mon Sep 17 00:00:00 2001 From: Valeri Karpov Date: Mon, 30 Dec 2024 15:08:44 -0500 Subject: [PATCH 2/3] Update test/types/populate.test.ts Co-authored-by: hasezoey --- test/types/populate.test.ts | 3 --- 1 file changed, 3 deletions(-) diff --git a/test/types/populate.test.ts b/test/types/populate.test.ts index 792971ed6c..9bb6635b54 100644 --- a/test/types/populate.test.ts +++ b/test/types/populate.test.ts @@ -491,9 +491,6 @@ async function gh15111() { required: true, trim: true } - }, - { - optimisticConcurrency: true } ); const ChildModel = mongoose.model('Child', childSchema); From e3c8756ec3851aa9fead3f7888db7647065624e5 Mon Sep 17 00:00:00 2001 From: Valeri Karpov Date: Mon, 30 Dec 2024 15:08:50 -0500 Subject: [PATCH 3/3] Update test/types/populate.test.ts Co-authored-by: hasezoey --- test/types/populate.test.ts | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/test/types/populate.test.ts b/test/types/populate.test.ts index 9bb6635b54..47eb053a5e 100644 --- a/test/types/populate.test.ts +++ b/test/types/populate.test.ts @@ -538,8 +538,7 @@ async function gh15111() { ref: 'Child', required: true } - }, - { optimisticConcurrency: true } + } ); parentSchema.virtual('fullName').get(function() {