Skip to content

Commit

Permalink
Fix incorrect type signature of Having (#3719)
Browse files Browse the repository at this point in the history
  • Loading branch information
lorefnon committed Mar 11, 2020
1 parent c309c98 commit acf56b5
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 9 deletions.
27 changes: 18 additions & 9 deletions types/index.d.ts
Expand Up @@ -1048,22 +1048,26 @@ declare namespace Knex {
WhereWrapped<TRecord, TResult>,
WhereNull<TRecord, TResult> {
(raw: Raw): QueryBuilder<TRecord, TResult>;

(callback: QueryCallback): QueryBuilder<TRecord, TResult>;

(object: Readonly<SafePartial<TRecord>>): QueryBuilder<TRecord, TResult>;

(object: Readonly<Object>): QueryBuilder<TRecord, TResult>;

<T extends keyof TRecord>(
columnName: T,
value: TRecord[T] | null
): QueryBuilder<TRecord, TResult>;

(columnName: string, value: Value | null): QueryBuilder<TRecord, TResult>;

<T extends keyof TRecord>(
columnName: T,
operator: ComparisonOperator,
value: TRecord[T] | null
): QueryBuilder<TRecord, TResult>;

(columnName: string, operator: string, value: Value | null): QueryBuilder<
TRecord,
TResult
Expand All @@ -1074,6 +1078,7 @@ declare namespace Knex {
operator: ComparisonOperator,
value: QueryBuilder<TRecordInner, TResultInner>
): QueryBuilder<TRecord, TResult>;

<TRecordInner, TResultInner>(
columnName: string,
operator: string,
Expand All @@ -1084,6 +1089,7 @@ declare namespace Knex {
TRecord,
TResult
>;

<TRecordInner, TResultInner>(
left: Raw,
operator: string,
Expand Down Expand Up @@ -1231,20 +1237,23 @@ declare namespace Knex {
extends Intersect<TRecord, TResult> {}

interface Having<TRecord = any, TResult = unknown[]>
extends RawQueryBuilder<TRecord, TResult>,
WhereWrapped<TRecord, TResult> {
<K1 extends keyof TRecord, K2 extends keyof TRecord>(
tableName: string,
column1: K1,
extends WhereWrapped<TRecord, TResult> {
<K extends keyof TRecord>(
column: K,
operator: ComparisonOperator,
column2: K2
value: TRecord[K]
): QueryBuilder<TRecord, TResult>;

(
tableName: string,
column1: string,
column: string | Raw,
operator: string,
column2: string
value: Value | QueryBuilder | null
): QueryBuilder<TRecord, TResult>;

(raw: Raw): QueryBuilder<
TRecord,
TResult
>;
}

interface HavingRange<TRecord = any, TResult = unknown[]> {
Expand Down
10 changes: 10 additions & 0 deletions types/test.ts
Expand Up @@ -496,6 +496,16 @@ const main = async () => {
.orderBy('name', 'desc')
.having('age', '>', 10);

const u5: User[] = await knex('users')
.groupBy('count')
.orderBy('name', 'desc')
.having(knex.raw('age > ?', 10));

const u6: User[] = await knex('users')
.groupBy('count')
.orderBy('name', 'desc')
.having(knex.raw('age'), '>', 10);

// $ExpectType User[]
await knex<User>('users')
.groupBy('count')
Expand Down

0 comments on commit acf56b5

Please sign in to comment.