diff --git a/test/types/populate.test.ts b/test/types/populate.test.ts index d65d2cb35ad..5c019e3375b 100644 --- a/test/types/populate.test.ts +++ b/test/types/populate.test.ts @@ -365,7 +365,7 @@ async function gh13070() { const Parent = model('Parent', parentSchema); const Child = model('Child', childSchema); - const doc = await Parent.findOne(); + const doc = await Parent.findOne().orFail(); const doc2 = await Child.populate<{ child: IChild }>(doc, 'child'); - const name: string = doc.child.name; + const name: string = doc2.child.name; } diff --git a/types/models.d.ts b/types/models.d.ts index 51d078e1683..5a557d21d36 100644 --- a/types/models.d.ts +++ b/types/models.d.ts @@ -299,12 +299,22 @@ declare module 'mongoose' { modelName: string; /** Populates document references. */ - populate(docs: Array, options: PopulateOptions | Array | string, - callback?: Callback<(HydratedDocument)[]>): Promise>>; - populate(doc: any, options: PopulateOptions | Array | string, - callback?: Callback>): Promise>; - populate(docs: Array, options: PopulateOptions | Array | string): Promise>; - populate(docs: any, options: PopulateOptions | Array | string, callback?: Callback>): void; + populate( + docs: Array, + options: PopulateOptions | Array | string + ): Promise>>; + populate( + doc: any, + options: PopulateOptions | Array | string, + ): Promise>; + populate( + docs: Array, + options: PopulateOptions | Array | string + ): Promise, Paths>[]>; + populate( + doc: AnyObject, + options: PopulateOptions | Array | string + ): Promise, Paths>>; /** Casts and validates the given object against this model's schema, passing the given `context` to custom validators. */ validate(callback?: CallbackWithoutResult): Promise;