Skip to content

Commit 70685e0

Browse files
committed
fix: add support for Map
1 parent 903442a commit 70685e0

File tree

3 files changed

+12
-2
lines changed

3 files changed

+12
-2
lines changed

src/index.ts

+3
Original file line numberDiff line numberDiff line change
@@ -283,16 +283,19 @@ export type {
283283
InferIdType,
284284
IntegerType,
285285
IsAny,
286+
Join,
286287
KeysOfAType,
287288
KeysOfOtherType,
288289
MatchKeysAndValues,
290+
NestedPaths,
289291
NotAcceptedFields,
290292
NumericType,
291293
OneOrMore,
292294
OnlyFieldsOfType,
293295
OptionalId,
294296
Projection,
295297
ProjectionOperators,
298+
PropertyType,
296299
PullAllOperator,
297300
PullOperator,
298301
PushOperator,

src/mongo_types.ts

+5-1
Original file line numberDiff line numberDiff line change
@@ -454,7 +454,9 @@ export type PropertyType<Type, Property extends string> = string extends Propert
454454
? PropertyType<ArrayType, Rest>
455455
: unknown
456456
: Key extends keyof Type
457-
? PropertyType<Type[Key], Rest>
457+
? Type[Key] extends Map<string, infer MapType>
458+
? MapType
459+
: PropertyType<Type[Key], Rest>
458460
: unknown
459461
: unknown;
460462

@@ -476,6 +478,8 @@ export type NestedPaths<Type> = Type extends
476478
? []
477479
: Type extends ReadonlyArray<infer ArrayType>
478480
? [number, ...NestedPaths<ArrayType>]
481+
: Type extends Map<string, any>
482+
? [string]
479483
: // eslint-disable-next-line @typescript-eslint/ban-types
480484
Type extends object
481485
? {

test/types/community/collection/filterQuery.test-d.ts

+4-1
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ interface PetModel {
3636
playTimePercent: Decimal128; // bson Decimal128 type
3737
readonly friends?: ReadonlyArray<HumanModel>; // readonly array of objects
3838
playmates?: HumanModel[]; // writable array of objects
39+
laps?: Map<string, number>; // map field
3940
// Object with multiple nested levels
4041
meta?: {
4142
updatedAt?: Date;
@@ -122,6 +123,7 @@ collectionT.find({ 'friends.0.name': 'John' });
122123
collectionT.find({ 'playmates.0.name': 'John' });
123124
// supports arrays with primitive types
124125
collectionT.find({ 'treats.0': 'bone' });
126+
collectionT.find({ 'laps.foo': 123 });
125127

126128
// Handle special BSON types
127129
collectionT.find({ numOfPats: Long.fromBigInt(2n) });
@@ -135,11 +137,12 @@ collectionT.find({ 'friends.999999999999999999999999999999999999.name': 'John' }
135137
expectNotType<Filter<PetModel>>({ 'meta.updatedAt': 123 });
136138
expectNotType<Filter<PetModel>>({ 'meta.updatedAt': true });
137139
expectNotType<Filter<PetModel>>({ 'meta.updatedAt': 'now' });
138-
expectNotType<Filter<PetModel>>({ 'meta.deep.nested.level': '123' });
140+
expectNotType<Filter<PetModel>>({ 'meta.deep.nested.level': 'string' });
139141
expectNotType<Filter<PetModel>>({ 'meta.deep.nested.level': true });
140142
expectNotType<Filter<PetModel>>({ 'meta.deep.nested.level': new Date() });
141143
expectNotType<Filter<PetModel>>({ 'friends.0.name': 123 });
142144
expectNotType<Filter<PetModel>>({ 'playmates.0.name': 123 });
145+
expectNotType<Filter<PetModel>>({ 'laps.foo': 'string' });
143146
expectNotType<Filter<PetModel>>({ 'treats.0': 123 });
144147
expectNotType<Filter<PetModel>>({ 'numOfPats.__isLong__': true });
145148
expectNotType<Filter<PetModel>>({ 'playTimePercent.bytes.BYTES_PER_ELEMENT': 1 });

0 commit comments

Comments
 (0)