diff --git a/types/mongodb/index.d.ts b/types/mongodb/index.d.ts index 3354845633..284ddb4956 100644 --- a/types/mongodb/index.d.ts +++ b/types/mongodb/index.d.ts @@ -28,6 +28,7 @@ // Alberto Silva // Rauno Viskus // Piotr Błażejewicz +// Linus Unnebäck // Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped // TypeScript Version: 3.0 @@ -1279,10 +1280,10 @@ export type PullAllOperator = ({ export type UpdateQuery = { /** https://docs.mongodb.com/manual/reference/operator/update-field/ */ $currentDate?: OnlyFieldsOfType; - $inc?: OnlyFieldsOfType; + $inc?: OnlyFieldsOfType; $min?: MatchKeysAndValues; $max?: MatchKeysAndValues; - $mul?: OnlyFieldsOfType; + $mul?: OnlyFieldsOfType; $rename?: { [key: string]: string }; $set?: MatchKeysAndValues; $setOnInsert?: MatchKeysAndValues; diff --git a/types/mongodb/test/collection/updateX.ts b/types/mongodb/test/collection/updateX.ts index 96864cc3d6..46711a602a 100644 --- a/types/mongodb/test/collection/updateX.ts +++ b/types/mongodb/test/collection/updateX.ts @@ -17,6 +17,7 @@ async function run() { interface TestModel { stringField: string; numberField: number; + optionalNumberField?: number; dateField: Date; otherDateField: Date; oneMoreDateField: Date; @@ -44,6 +45,7 @@ async function run() { // buildUpdateQuery({ $currentDate: { stringField: true } }); // stringField is not a date Field buildUpdateQuery({ $inc: { numberField: 1 } }); + buildUpdateQuery({ $inc: { optionalNumberField: 1 } }); buildUpdateQuery({ $inc: { 'dot.notation': 2 } }); buildUpdateQuery({ $inc: { 'subInterfaceArray.$': -10 } }); buildUpdateQuery({ $inc: { 'subInterfaceArray.$[bla]': 40 } }); @@ -68,6 +70,7 @@ async function run() { // buildUpdateQuery({ $min: { numberField: 'a' } }); // Matches the type of the keys buildUpdateQuery({ $mul: { numberField: 1 } }); + buildUpdateQuery({ $mul: { optionalNumberField: 1 } }); buildUpdateQuery({ $mul: { 'dot.notation': 2 } }); buildUpdateQuery({ $mul: { 'subInterfaceArray.$': -10 } }); buildUpdateQuery({ $mul: { 'subInterfaceArray.$[bla]': 40 } });