Skip to content

Commit

Permalink
fix(types): clean up a couple of issues with $add and $ifNull
Browse files Browse the repository at this point in the history
Fix #12017
  • Loading branch information
vkarpov15 committed Jul 5, 2022
1 parent aa46617 commit 783ed75
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 2 deletions.
9 changes: 9 additions & 0 deletions test/types/expressions.test.ts
Expand Up @@ -86,6 +86,8 @@ const topN: Expression.TopN = {
}
};

const d: Expression.Avg = { $avg: { $subtract: [{ $ifNull: ['$end', new Date()] }, '$start'] } };

const dateSubtract1: Expression = {
$dateSubtract:
{
Expand Down Expand Up @@ -167,6 +169,13 @@ const letExpr: Expression = {
}
};

const addWithNull: Expression.Add = {
$add: [
'$price',
{ $ifNull: ['$tax', 0] }
]
}

const toLong: Expression = { $toLong: '$qty' };

const nullExpr: Expression = {
Expand Down
4 changes: 2 additions & 2 deletions types/expressions.d.ts
Expand Up @@ -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 {
Expand Down Expand Up @@ -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 {
Expand Down

0 comments on commit 783ed75

Please sign in to comment.