Skip to content

Commit

Permalink
test: add test case for #11960
Browse files Browse the repository at this point in the history
  • Loading branch information
vkarpov15 committed Jun 24, 2022
1 parent 5409717 commit 5753bce
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 0 deletions.
1 change: 1 addition & 0 deletions .eslintrc.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
],
"rules": {
"@typescript-eslint/triple-slash-reference": "off",
"@typescript-eslint/no-non-null-assertion": "off",
"spaced-comment": [
"error",
"always",
Expand Down
41 changes: 41 additions & 0 deletions test/types/document.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -196,4 +196,45 @@ function autoTypedDocument() {
// Document-Methods-tests
expectType<ReturnType<AutoTypedSchemaType['methods']['instanceFn']>>(new AutoTypedModel().instanceFn());

}

async function gh11960() {
type DocumentType<T> = Document<any> & T;
type SubDocumentType<T> = DocumentType<T> & Types.Subdocument;
type ArraySubDocumentType<T> = DocumentType<T> & Types.ArraySubdocument;

interface Nested {
dummy?: string;
}

interface Parent {
username?: string;
map?: Map<string, string>;
nested?: SubDocumentType<Nested>;
nestedArray?: ArraySubDocumentType<Nested>[];
}

const NestedSchema = new Schema({
dummy: { type: String }
});

const ParentSchema = new Schema({
username: { type: String },
map: { type: Map, of: String },
nested: { type: NestedSchema },
nestedArray: [{ type: NestedSchema }]
});

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();

}

0 comments on commit 5753bce

Please sign in to comment.