From 783ed7554ba15359939255b11d98db56c3ee28a2 Mon Sep 17 00:00:00 2001 From: Valeri Karpov Date: Tue, 5 Jul 2022 10:40:25 -0400 Subject: [PATCH] fix(types): clean up a couple of issues with `$add` and `$ifNull` Fix #12017 --- test/types/expressions.test.ts | 9 +++++++++ types/expressions.d.ts | 4 ++-- 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/test/types/expressions.test.ts b/test/types/expressions.test.ts index ba71d9a2fb8..433615cc7ff 100644 --- a/test/types/expressions.test.ts +++ b/test/types/expressions.test.ts @@ -86,6 +86,8 @@ const topN: Expression.TopN = { } }; +const d: Expression.Avg = { $avg: { $subtract: [{ $ifNull: ['$end', new Date()] }, '$start'] } }; + const dateSubtract1: Expression = { $dateSubtract: { @@ -167,6 +169,13 @@ const letExpr: Expression = { } }; +const addWithNull: Expression.Add = { + $add: [ + '$price', + { $ifNull: ['$tax', 0] } + ] +} + const toLong: Expression = { $toLong: '$qty' }; const nullExpr: Expression = { diff --git a/types/expressions.d.ts b/types/expressions.d.ts index 865c26ff319..221ab22d5a5 100644 --- a/types/expressions.d.ts +++ b/types/expressions.d.ts @@ -32,7 +32,7 @@ declare module 'mongoose' { * * @see https://docs.mongodb.com/manual/reference/operator/aggregation/add/#mongodb-expression-exp.-add */ - $add: (NumberExpression | DateExpression)[]; + $add: Expression[]; } export interface Ceil { @@ -1967,7 +1967,7 @@ declare module 'mongoose' { * @version 5.0 * @see https://docs.mongodb.com/manual/reference/operator/aggregation/avg/#mongodb-expression-exp.-avg */ - $avg: ArrayExpression; + $avg: Expression; } export interface Count {