From ce4d4586159606fa36e1ce976ce92b3c593e89c1 Mon Sep 17 00:00:00 2001 From: Valeri Karpov Date: Fri, 1 Jul 2022 13:14:50 -0400 Subject: [PATCH] test(types): repro #11955 --- test/types/populate.test.ts | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/test/types/populate.test.ts b/test/types/populate.test.ts index 8423c270272..95d0d2f1a58 100644 --- a/test/types/populate.test.ts +++ b/test/types/populate.test.ts @@ -298,3 +298,28 @@ function gh11758() { expectType(parent.nestedChild.name); } + +async function gh11955() { + // `Parent` represents the object as it is stored in MongoDB + interface Parent { + children?: Types.ObjectId[], + name?: string + } + + const ParentModel = model('Parent', new Schema({ + children: [{ type: Schema.Types.ObjectId, ref: 'Child' }], + name: String + })); + + interface Child { + name: string; + } + const childSchema: Schema = new Schema({ name: String }); + model('Child', childSchema); + + const parent = await ParentModel.findOne({}).exec(); + + const populatedParent = await parent!.populate<{ children: Child[] }>('child'); + + populatedParent.children.find(({ name }) => console.log(name)); +}