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

types(schematypes): allow defining map path using type: 'Map' in addition to type: Map #13960

Merged
merged 3 commits into from
Oct 10, 2023
Merged
Show file tree
Hide file tree
Changes from 2 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
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>({
vkarpov15 marked this conversation as resolved.
Show resolved Hide resolved
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