diff --git a/test/types/PipelineStage.test.ts b/test/types/PipelineStage.test.ts index 5c97a53fd41..37968a3b366 100644 --- a/test/types/PipelineStage.test.ts +++ b/test/types/PipelineStage.test.ts @@ -392,3 +392,26 @@ const stages3: PipelineStage[] = [ } } ]; + +const stages4: PipelineStage[] = [ + { + $addFields: { + usersCount: { + $let: { + vars: { + users: { $push: '$user' } + }, + in: { + $reduce: { + input: '$users', + initialValue: 0, + in: { + $cond: { if: { $isArray: '$$this' }, then: { $size: '$$this' }, else: '$$this' } + } + } + } + } + } + } + } +]; diff --git a/types/expressions.d.ts b/types/expressions.d.ts index 53a7ca7ce38..8624b155b6c 100644 --- a/types/expressions.d.ts +++ b/types/expressions.d.ts @@ -2448,7 +2448,8 @@ declare module 'mongoose' { BinaryExpression | FunctionExpression | ObjectIdExpression | - ConditionalExpressionOperator; + ConditionalExpressionOperator | + Expression.Let; export type ObjectIdExpression = TypeExpressionOperatorReturningObjectId;