From e7b9a4d8b9dbef2dbc108547bdf24543c05e6e22 Mon Sep 17 00:00:00 2001 From: Hafez Date: Mon, 11 Jul 2022 15:03:45 +0200 Subject: [PATCH 1/2] test(types): test $switch expression type --- test/types/expressions.test.ts | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/test/types/expressions.test.ts b/test/types/expressions.test.ts index a078f3a0777..00509363c07 100644 --- a/test/types/expressions.test.ts +++ b/test/types/expressions.test.ts @@ -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' + } +}; From 9f906b619fdb7a32aeaf2072734d3971363936d9 Mon Sep 17 00:00:00 2001 From: Hafez Date: Mon, 11 Jul 2022 15:05:54 +0200 Subject: [PATCH 2/2] fix(types): fix $switch expression type --- types/expressions.d.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/types/expressions.d.ts b/types/expressions.d.ts index 10ee0bf1559..53a7ca7ce38 100644 --- a/types/expressions.d.ts +++ b/types/expressions.d.ts @@ -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; }; }