Skip to content

Commit

Permalink
test(types): repro #11955
Browse files Browse the repository at this point in the history
  • Loading branch information
vkarpov15 committed Jul 1, 2022
1 parent de77099 commit ce4d458
Showing 1 changed file with 25 additions and 0 deletions.
25 changes: 25 additions & 0 deletions test/types/populate.test.ts
Expand Up @@ -298,3 +298,28 @@ function gh11758() {

expectType<string>(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>('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>('Child', childSchema);

const parent = await ParentModel.findOne({}).exec();

const populatedParent = await parent!.populate<{ children: Child[] }>('child');

populatedParent.children.find(({ name }) => console.log(name));
}

0 comments on commit ce4d458

Please sign in to comment.