Skip to content

Commit

Permalink
fix tests, fix #13070
Browse files Browse the repository at this point in the history
  • Loading branch information
vkarpov15 committed Mar 2, 2023
1 parent b7417ba commit 66d0235
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 8 deletions.
4 changes: 2 additions & 2 deletions test/types/populate.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -365,7 +365,7 @@ async function gh13070() {
const Parent = model<IParent>('Parent', parentSchema);
const Child = model<IChild>('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;
}
22 changes: 16 additions & 6 deletions types/models.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -299,12 +299,22 @@ declare module 'mongoose' {
modelName: string;

/** Populates document references. */
populate(docs: Array<any>, options: PopulateOptions | Array<PopulateOptions> | string,
callback?: Callback<(HydratedDocument<T, TMethodsAndOverrides, TVirtuals>)[]>): Promise<Array<HydratedDocument<T, TMethodsAndOverrides, TVirtuals>>>;
populate(doc: any, options: PopulateOptions | Array<PopulateOptions> | string,
callback?: Callback<HydratedDocument<T, TMethodsAndOverrides, TVirtuals>>): Promise<HydratedDocument<T, TMethodsAndOverrides, TVirtuals>>;
populate<Paths={}>(docs: Array<any>, options: PopulateOptions | Array<PopulateOptions> | string): Promise<MergeType<this, Paths>>;
populate<Paths={}>(docs: any, options: PopulateOptions | Array<PopulateOptions> | string, callback?: Callback<MergeType<this, Paths>>): void;
populate(
docs: Array<any>,
options: PopulateOptions | Array<PopulateOptions> | string
): Promise<Array<HydratedDocument<T, TMethodsAndOverrides, TVirtuals>>>;
populate(
doc: any,
options: PopulateOptions | Array<PopulateOptions> | string,
): Promise<HydratedDocument<T, TMethodsAndOverrides, TVirtuals>>;
populate<Paths>(
docs: Array<any>,
options: PopulateOptions | Array<PopulateOptions> | string
): Promise<MergeType<HydratedDocument<T, TMethodsAndOverrides, TVirtuals>, Paths>[]>;
populate<Paths>(
doc: AnyObject,
options: PopulateOptions | Array<PopulateOptions> | string
): Promise<MergeType<HydratedDocument<T, TMethodsAndOverrides, TVirtuals>, Paths>>;

/** Casts and validates the given object against this model's schema, passing the given `context` to custom validators. */
validate(callback?: CallbackWithoutResult): Promise<void>;
Expand Down

0 comments on commit 66d0235

Please sign in to comment.