From 8a6cfa55f546f4f91d0140607783692898573339 Mon Sep 17 00:00:00 2001 From: boenfu <1997@boenfu.cn> Date: Wed, 30 Mar 2022 16:35:58 +0800 Subject: [PATCH 1/3] fix: fix array field NestedPaths return type --- src/mongo_types.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/mongo_types.ts b/src/mongo_types.ts index 83bf11ad6a..c94a360645 100644 --- a/src/mongo_types.ts +++ b/src/mongo_types.ts @@ -515,7 +515,7 @@ export type NestedPaths = Type extends ArrayType extends Type ? [Key] // we have a recursive array union : // child is an array, but it's not a recursive array - [Key, ...NestedPaths] + [Key] | [Key, ...NestedPaths] : // child is not structured the same as the parent [Key, ...NestedPaths]; }[Extract] From 5ee842050ecca441b6366ddafb43cff3392f7a63 Mon Sep 17 00:00:00 2001 From: boenfu <1997@boenfu.cn> Date: Thu, 31 Mar 2022 11:14:06 +0800 Subject: [PATCH 2/3] test: add missing array fields tests --- test/types/community/collection/filterQuery.test-d.ts | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/test/types/community/collection/filterQuery.test-d.ts b/test/types/community/collection/filterQuery.test-d.ts index 53c83f586f..2f4d7f7e53 100644 --- a/test/types/community/collection/filterQuery.test-d.ts +++ b/test/types/community/collection/filterQuery.test-d.ts @@ -204,6 +204,14 @@ expectNotType>({ 'playmates.0.name': 123 }); expectNotType>({ 'laps.foo': 'string' }); expectNotType>({ 'treats.0': 123 }); +/// it should not accept wrong types for nested document array fields +expectError>({ + treats: { + $elemMatch: true + } +}); +expectError>({ treats: 123 }); + // Nested arrays aren't checked expectNotType>({ 'meta.deep.nestedArray.0': 'not a number' }); From 64574d6ef3ef44c37c63985b82663ca18d09752e Mon Sep 17 00:00:00 2001 From: boenfu <1997@boenfu.cn> Date: Fri, 1 Apr 2022 12:14:35 +0800 Subject: [PATCH 3/3] fix: fix nested paths for array field --- src/mongo_types.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/mongo_types.ts b/src/mongo_types.ts index c94a360645..fbbb2a475c 100644 --- a/src/mongo_types.ts +++ b/src/mongo_types.ts @@ -496,7 +496,7 @@ export type NestedPaths = Type extends | { _bsontype: string } ? [] : Type extends ReadonlyArray - ? [number, ...NestedPaths] + ? [] | [number, ...NestedPaths] : Type extends Map ? [string] : // eslint-disable-next-line @typescript-eslint/ban-types @@ -515,7 +515,7 @@ export type NestedPaths = Type extends ArrayType extends Type ? [Key] // we have a recursive array union : // child is an array, but it's not a recursive array - [Key] | [Key, ...NestedPaths] + [Key, ...NestedPaths] : // child is not structured the same as the parent [Key, ...NestedPaths]; }[Extract]