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)); +}