Skip to content

Commit

Permalink
Merge pull request #12088 from Automattic/ts-fix-switch
Browse files Browse the repository at this point in the history
fix(types): fix $switch expression type
  • Loading branch information
vkarpov15 committed Jul 15, 2022
2 parents dfc2fd1 + 9f906b6 commit 3e5fa8c
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 2 deletions.
10 changes: 10 additions & 0 deletions test/types/expressions.test.ts
Expand Up @@ -193,3 +193,13 @@ const nullExpr: Expression = {
const nullNETupleExpr: Expression = {
$ne: ['$name', null]
};

const switchExpr: Expression.Switch = {
$switch: {
branches: [
{ case: { $eq: ['$name', 'Detlef'] }, then: 'Detlef' },
{ case: { $eq: ['$name', 'John'] }, then: 'John' }
],
default: 'Hello'
}
};
4 changes: 2 additions & 2 deletions types/expressions.d.ts
Expand Up @@ -1067,13 +1067,13 @@ declare module 'mongoose' {
* - $case
* - $then
*/
$branches: { $case: Expression, then: Expression }[];
branches: { case: Expression, then: Expression }[];
/**
* The path to take if no branch case expression evaluates to true.
*
* Although optional, if default is unspecified and no branch case evaluates to true, $switch returns an error.
*/
$default: Expression;
default: Expression;
};
}

Expand Down

0 comments on commit 3e5fa8c

Please sign in to comment.