Skip to content

Commit 660ea80

Browse files
authored
Merge pull request #13960 from Automattic/vkarpov15/gh-13755
types(schematypes): allow defining map path using `type: 'Map'` in addition to `type: Map`
2 parents 3042ac1 + c4416a6 commit 660ea80

File tree

2 files changed

+15
-1
lines changed

2 files changed

+15
-1
lines changed

test/types/maps.test.ts

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import { Schema, model, Document, Model, Types } from 'mongoose';
2+
import { expectType } from 'tsd';
23

34
interface ITest {
45
map1: Map<string, number>,
@@ -71,3 +72,16 @@ function gh10872(): void {
7172

7273
doc.toJSON().map1.foo;
7374
}
75+
76+
function gh13755() {
77+
const testSchema = new Schema({
78+
instance: {
79+
type: 'Map',
80+
of: String
81+
}
82+
} as const);
83+
84+
const TestModel = model('Test', testSchema);
85+
const doc = new TestModel();
86+
expectType<Map<string, string> | undefined>(doc.instance);
87+
}

types/inferschematype.d.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -219,7 +219,7 @@ type ResolvePathType<PathValueType, Options extends SchemaTypeOptions<PathValueT
219219
PathValueType extends 'bigint' | 'BigInt' | typeof Schema.Types.BigInt ? bigint :
220220
PathValueType extends 'uuid' | 'UUID' | typeof Schema.Types.UUID ? Buffer :
221221
IfEquals<PathValueType, Schema.Types.UUID> extends true ? Buffer :
222-
PathValueType extends MapConstructor ? Map<string, ResolvePathType<Options['of']>> :
222+
PathValueType extends MapConstructor | 'Map' ? Map<string, ResolvePathType<Options['of']>> :
223223
IfEquals<PathValueType, typeof Schema.Types.Map> extends true ? Map<string, ResolvePathType<Options['of']>> :
224224
PathValueType extends ArrayConstructor ? any[] :
225225
PathValueType extends typeof Schema.Types.Mixed ? any:

0 commit comments

Comments
 (0)