Skip to content

Commit

Permalink
types(schematypes): allow defining map path using type: 'Map' in ad…
Browse files Browse the repository at this point in the history
…dition to `type: Map`

Fix #13755
  • Loading branch information
vkarpov15 committed Oct 9, 2023
1 parent b721f54 commit 098c644
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 2 deletions.
16 changes: 16 additions & 0 deletions test/types/maps.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -71,3 +71,19 @@ function gh10872(): void {

doc.toJSON().map1.foo;
}

function gh13755() {
class Test {
instance: Map<string, string>;
constructor() {
this.instance = new Map<string, string>();
}
}

const testSchema = new Schema<Test>({
instance: {
type: 'Map',
of: 'Mixed'
}
});
}
2 changes: 1 addition & 1 deletion test/types/schemaTypeOptions.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ expectType<BooleanSchemaDefinition | undefined>(new SchemaTypeOptions<boolean>()
expectType<NumberSchemaDefinition | undefined>(new SchemaTypeOptions<number>().type);
expectType<DateSchemaDefinition | undefined>(new SchemaTypeOptions<Date>().type);
expectType<StringSchemaDefinition | undefined>(new SchemaTypeOptions<string>().type);
expectType<SchemaDefinition<typeof Map> | undefined>(new SchemaTypeOptions<Map<any, any>>().type);
expectType<SchemaDefinition<typeof Map> | SchemaDefinition<'Map'> | undefined>(new SchemaTypeOptions<Map<any, any>>().type);
expectType<SchemaDefinition<typeof Buffer> | undefined>(new SchemaTypeOptions<Buffer>().type);
expectType<ObjectIdSchemaDefinition | undefined>(new SchemaTypeOptions<Types.ObjectId>().type);
expectType<AnyArray<ObjectIdSchemaDefinition> | AnyArray<SchemaTypeOptions<ObjectId>> | undefined>(new SchemaTypeOptions<Types.ObjectId[]>().type);
Expand Down
2 changes: 1 addition & 1 deletion types/schematypes.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ declare module 'mongoose' {
T extends number ? NumberSchemaDefinition :
T extends boolean ? BooleanSchemaDefinition :
T extends NativeDate ? DateSchemaDefinition :
T extends Map<any, any> ? SchemaDefinition<typeof Map> :
T extends Map<any, any> ? SchemaDefinition<typeof Map> | SchemaDefinition<'Map'> :
T extends Buffer ? SchemaDefinition<typeof Buffer> :
T extends Types.ObjectId ? ObjectIdSchemaDefinition :
T extends Types.ObjectId[] ? AnyArray<ObjectIdSchemaDefinition> | AnyArray<SchemaTypeOptions<ObjectId, EnforcedDocType>> :
Expand Down

0 comments on commit 098c644

Please sign in to comment.