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 all 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
14 changes: 14 additions & 0 deletions test/types/maps.test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { Schema, model, Document, Model, Types } from 'mongoose';
import { expectType } from 'tsd';

interface ITest {
map1: Map<string, number>,
Expand Down Expand Up @@ -71,3 +72,16 @@ function gh10872(): void {

doc.toJSON().map1.foo;
}

function gh13755() {
const testSchema = new Schema({
instance: {
type: 'Map',
of: String
}
} as const);

const TestModel = model('Test', testSchema);
const doc = new TestModel();
expectType<Map<string, string> | undefined>(doc.instance);
}
2 changes: 1 addition & 1 deletion types/inferschematype.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -219,7 +219,7 @@ type ResolvePathType<PathValueType, Options extends SchemaTypeOptions<PathValueT
PathValueType extends 'bigint' | 'BigInt' | typeof Schema.Types.BigInt ? bigint :
PathValueType extends 'uuid' | 'UUID' | typeof Schema.Types.UUID ? Buffer :
IfEquals<PathValueType, Schema.Types.UUID> extends true ? Buffer :
PathValueType extends MapConstructor ? Map<string, ResolvePathType<Options['of']>> :
PathValueType extends MapConstructor | 'Map' ? Map<string, ResolvePathType<Options['of']>> :
IfEquals<PathValueType, typeof Schema.Types.Map> extends true ? Map<string, ResolvePathType<Options['of']>> :
PathValueType extends ArrayConstructor ? any[] :
PathValueType extends typeof Schema.Types.Mixed ? any:
Expand Down