mirror of
https://github.com/gosticks/DefinitelyTyped.git
synced 2026-06-28 22:30:01 +00:00
[mongodb] Allow optional fields in $inc and $mul (#42821)
This commit is contained in:
5
types/mongodb/index.d.ts
vendored
5
types/mongodb/index.d.ts
vendored
@@ -28,6 +28,7 @@
|
||||
// Alberto Silva <https://github.com/albertossilva>
|
||||
// Rauno Viskus <https://github.com/Rauno56>
|
||||
// Piotr Błażejewicz <https://github.com/peterblazejewicz>
|
||||
// Linus Unnebäck <https://github.com/LinusU>
|
||||
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
|
||||
// TypeScript Version: 3.0
|
||||
|
||||
@@ -1279,10 +1280,10 @@ export type PullAllOperator<TSchema> = ({
|
||||
export type UpdateQuery<TSchema> = {
|
||||
/** https://docs.mongodb.com/manual/reference/operator/update-field/ */
|
||||
$currentDate?: OnlyFieldsOfType<TSchema, Date, true | { $type: 'date' | 'timestamp' }>;
|
||||
$inc?: OnlyFieldsOfType<TSchema, number>;
|
||||
$inc?: OnlyFieldsOfType<TSchema, number | undefined>;
|
||||
$min?: MatchKeysAndValues<TSchema>;
|
||||
$max?: MatchKeysAndValues<TSchema>;
|
||||
$mul?: OnlyFieldsOfType<TSchema, number>;
|
||||
$mul?: OnlyFieldsOfType<TSchema, number | undefined>;
|
||||
$rename?: { [key: string]: string };
|
||||
$set?: MatchKeysAndValues<TSchema>;
|
||||
$setOnInsert?: MatchKeysAndValues<TSchema>;
|
||||
|
||||
@@ -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 } });
|
||||
|
||||
Reference in New Issue
Block a user