Skip to content

Commit

Permalink
Merge pull request #12001 from hasezoey/extendTypesTestFor11960
Browse files Browse the repository at this point in the history
Extend types test for #11960
  • Loading branch information
vkarpov15 committed Jul 1, 2022
2 parents fec4d6a + b6b0973 commit 39f651c
Showing 1 changed file with 26 additions and 9 deletions.
35 changes: 26 additions & 9 deletions test/types/document.test.ts
Expand Up @@ -227,14 +227,31 @@ async function gh11960() {

const ParentModel = model<DocumentType<Parent>>('Parent', ParentSchema);

const doc = new ParentModel({
username: 'user1',
map: { key1: 'value1', key2: 'value2' },
nested: { dummy: 'hello' },
nestedArray: [{ dummy: 'hello again' }]
});

expectType<Map<string, string> | undefined>(doc.map);
doc.nested!.parent();
{
const doc = new ParentModel({
username: 'user1',
map: { key1: 'value1', key2: 'value2' },
nested: { dummy: 'hello' },
nestedArray: [{ dummy: 'hello again' }]
});

expectType<Document<any, any, any> & Parent & { _id: Types.ObjectId }>(doc);
expectType<Map<string, string> | undefined>(doc.map);
doc.nested!.parent();
doc.nestedArray?.[0].parentArray();
}

{
const doc = await ParentModel.create({
username: 'user1',
map: { key1: 'value1', key2: 'value2' },
nested: { dummy: 'hello' },
nestedArray: [{ dummy: 'hello again' }]
});

expectType<Document<any, any, any> & Parent & { _id: Types.ObjectId }>(doc);
expectType<Map<string, string> | undefined>(doc.map);
doc.nested!.parent();
doc.nestedArray?.[0].parentArray();
}
}

0 comments on commit 39f651c

Please sign in to comment.