From c46c984f42bceca671b6d186a814881e0700b662 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=A0=BC=E6=A1=91?= <33797740+boenfu@users.noreply.github.com> Date: Wed, 6 Apr 2022 02:15:50 +0800 Subject: [PATCH] fix(NODE-4133): array field NestedPaths return type (#3184) --- src/mongo_types.ts | 2 +- test/types/community/collection/filterQuery.test-d.ts | 8 ++++++++ 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/src/mongo_types.ts b/src/mongo_types.ts index 83bf11ad6a..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 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' });