Skip to content

Commit c46c984

Browse files
authored
fix(NODE-4133): array field NestedPaths return type (#3184)
1 parent 3dba3ae commit c46c984

File tree

2 files changed

+9
-1
lines changed

2 files changed

+9
-1
lines changed

src/mongo_types.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -496,7 +496,7 @@ export type NestedPaths<Type> = Type extends
496496
| { _bsontype: string }
497497
? []
498498
: Type extends ReadonlyArray<infer ArrayType>
499-
? [number, ...NestedPaths<ArrayType>]
499+
? [] | [number, ...NestedPaths<ArrayType>]
500500
: Type extends Map<string, any>
501501
? [string]
502502
: // eslint-disable-next-line @typescript-eslint/ban-types

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

+8
Original file line numberDiff line numberDiff line change
@@ -204,6 +204,14 @@ expectNotType<Filter<PetModel>>({ 'playmates.0.name': 123 });
204204
expectNotType<Filter<PetModel>>({ 'laps.foo': 'string' });
205205
expectNotType<Filter<PetModel>>({ 'treats.0': 123 });
206206

207+
/// it should not accept wrong types for nested document array fields
208+
expectError<Filter<PetModel>>({
209+
treats: {
210+
$elemMatch: true
211+
}
212+
});
213+
expectError<Filter<PetModel>>({ treats: 123 });
214+
207215
// Nested arrays aren't checked
208216
expectNotType<Filter<PetModel>>({ 'meta.deep.nestedArray.0': 'not a number' });
209217

0 commit comments

Comments
 (0)