Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[TypeScript] Add Object syntax overload to increment method #5512

Merged
merged 1 commit into from
Mar 28, 2023

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.

None yet

3 participants