From 9fcfabaa5905a474c266eb57e6c70a4f61f3aaac Mon Sep 17 00:00:00 2001 From: Luca Kiebel Date: Tue, 7 Mar 2023 16:24:06 +0100 Subject: [PATCH] [TypeScript] Add Object syntax overload to increment method The [documentation for `QueryBuilder#icrements`](https://knexjs.org/guide/query-builder.html#increment) says, that the method accepts columns and values either as separate arguments, or in Object syntax ([the code also checks if the column is an object](https://github.com/knex/knex/blob/0d27bcb60b9bfd57fabf896715350089e0b1050c/lib/query/querybuilder.js#L1111)). But currently this code: ````typescript knex("table") .where({ id: 1 }) .increment({ foo: 1, bar: 2, }); ```` Throws an error: ```` No overload matches this call. Overload 1 of 2, '(columnName: string | number | symbol, amount?: number): QueryBuilder', gave the following error. Argument of type '{ views: number; clicks: number; sales: number; }' is not assignable to parameter of type 'string | number | symbol'. Overload 2 of 2, '(columnName: string, amount?: number): QueryBuilder', gave the following error. Argument of type '{ views: number; clicks: number; sales: number; }' is not assignable to parameter of type 'string'. ```` This adds an overload to the increment method type definition for the case where the first argument is an Object consisting of keys from TRecord and numbers as values. --- types/index.d.ts | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/types/index.d.ts b/types/index.d.ts index 70f93ee87e..f386076df7 100644 --- a/types/index.d.ts +++ b/types/index.d.ts @@ -788,6 +788,11 @@ export declare namespace Knex { columnName: string, amount?: number ): QueryBuilder; + increment( + columns: { + [column in keyof TRecord]: number + } + ): QueryBuilder; decrement( columnName: keyof TRecord,