Skip to content

Commit

Permalink
fix(NODE-4133): array field NestedPaths return type (#3184)
Browse files Browse the repository at this point in the history
  • Loading branch information
boenfu authored Apr 5, 2022
1 parent 3dba3ae commit c46c984
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/mongo_types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -496,7 +496,7 @@ export type NestedPaths<Type> = Type extends
| { _bsontype: string }
? []
: Type extends ReadonlyArray<infer ArrayType>
? [number, ...NestedPaths<ArrayType>]
? [] | [number, ...NestedPaths<ArrayType>]
: Type extends Map<string, any>
? [string]
: // eslint-disable-next-line @typescript-eslint/ban-types
Expand Down
8 changes: 8 additions & 0 deletions test/types/community/collection/filterQuery.test-d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -204,6 +204,14 @@ expectNotType<Filter<PetModel>>({ 'playmates.0.name': 123 });
expectNotType<Filter<PetModel>>({ 'laps.foo': 'string' });
expectNotType<Filter<PetModel>>({ 'treats.0': 123 });

/// it should not accept wrong types for nested document array fields
expectError<Filter<PetModel>>({
treats: {
$elemMatch: true
}
});
expectError<Filter<PetModel>>({ treats: 123 });

// Nested arrays aren't checked
expectNotType<Filter<PetModel>>({ 'meta.deep.nestedArray.0': 'not a number' });

Expand Down

0 comments on commit c46c984

Please sign in to comment.