Skip to content

Commit 783ed75

Browse files
committed
fix(types): clean up a couple of issues with $add and $ifNull
Fix #12017
1 parent aa46617 commit 783ed75

File tree

2 files changed

+11
-2
lines changed

2 files changed

+11
-2
lines changed

test/types/expressions.test.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,8 @@ const topN: Expression.TopN = {
8686
}
8787
};
8888

89+
const d: Expression.Avg = { $avg: { $subtract: [{ $ifNull: ['$end', new Date()] }, '$start'] } };
90+
8991
const dateSubtract1: Expression = {
9092
$dateSubtract:
9193
{
@@ -167,6 +169,13 @@ const letExpr: Expression = {
167169
}
168170
};
169171

172+
const addWithNull: Expression.Add = {
173+
$add: [
174+
'$price',
175+
{ $ifNull: ['$tax', 0] }
176+
]
177+
}
178+
170179
const toLong: Expression = { $toLong: '$qty' };
171180

172181
const nullExpr: Expression = {

types/expressions.d.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ declare module 'mongoose' {
3232
*
3333
* @see https://docs.mongodb.com/manual/reference/operator/aggregation/add/#mongodb-expression-exp.-add
3434
*/
35-
$add: (NumberExpression | DateExpression)[];
35+
$add: Expression[];
3636
}
3737

3838
export interface Ceil {
@@ -1967,7 +1967,7 @@ declare module 'mongoose' {
19671967
* @version 5.0
19681968
* @see https://docs.mongodb.com/manual/reference/operator/aggregation/avg/#mongodb-expression-exp.-avg
19691969
*/
1970-
$avg: ArrayExpression;
1970+
$avg: Expression;
19711971
}
19721972

19731973
export interface Count {

0 commit comments

Comments
 (0)