Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Conversation

lucakiebel
Copy link
Contributor

The documentation for QueryBuilder#icrement 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).

But currently this code:

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<any, number>', gave the following error.
    Argument of type '{ foo: number; bar: number; }' is not assignable to parameter of type 'string | number | symbol'.
  Overload 2 of 2, '(columnName: string, amount?: number): QueryBuilder<any, number>', gave the following error.
    Argument of type '{ foo: number; bar: 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.

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<any, number>', 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<any, number>', 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.
@coveralls
Copy link

Coverage Status

Coverage: 92.392%. Remained the same when pulling 9fcfaba on lucakiebel:patch-1 into 0d27bcb on knex:master.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants