Skip to content

Commit 5753bce

Browse files
committed
test: add test case for #11960
1 parent 5409717 commit 5753bce

File tree

2 files changed

+42
-0
lines changed

2 files changed

+42
-0
lines changed

.eslintrc.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
],
2525
"rules": {
2626
"@typescript-eslint/triple-slash-reference": "off",
27+
"@typescript-eslint/no-non-null-assertion": "off",
2728
"spaced-comment": [
2829
"error",
2930
"always",

test/types/document.test.ts

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -196,4 +196,45 @@ function autoTypedDocument() {
196196
// Document-Methods-tests
197197
expectType<ReturnType<AutoTypedSchemaType['methods']['instanceFn']>>(new AutoTypedModel().instanceFn());
198198

199+
}
200+
201+
async function gh11960() {
202+
type DocumentType<T> = Document<any> & T;
203+
type SubDocumentType<T> = DocumentType<T> & Types.Subdocument;
204+
type ArraySubDocumentType<T> = DocumentType<T> & Types.ArraySubdocument;
205+
206+
interface Nested {
207+
dummy?: string;
208+
}
209+
210+
interface Parent {
211+
username?: string;
212+
map?: Map<string, string>;
213+
nested?: SubDocumentType<Nested>;
214+
nestedArray?: ArraySubDocumentType<Nested>[];
215+
}
216+
217+
const NestedSchema = new Schema({
218+
dummy: { type: String }
219+
});
220+
221+
const ParentSchema = new Schema({
222+
username: { type: String },
223+
map: { type: Map, of: String },
224+
nested: { type: NestedSchema },
225+
nestedArray: [{ type: NestedSchema }]
226+
});
227+
228+
const ParentModel = model<DocumentType<Parent>>('Parent', ParentSchema);
229+
230+
const doc = new ParentModel({
231+
username: 'user1',
232+
map: { key1: 'value1', key2: 'value2' },
233+
nested: { dummy: 'hello' },
234+
nestedArray: [{ dummy: 'hello again' }]
235+
});
236+
237+
expectType<Map<string, string> | undefined>(doc.map);
238+
doc.nested!.parent();
239+
199240
}

0 commit comments

Comments
 (0)