Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Extend types test for #11960 #12001

Merged
merged 2 commits into from Jul 1, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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();
}
}