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 missing types for havingNull and havingNotNull #5529

Merged
merged 3 commits into from Mar 29, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
22 changes: 22 additions & 0 deletions test-tsd/having.test-d.ts
@@ -0,0 +1,22 @@
import Knex from '../types';
import { clientConfig, User } from './common';
import { expectType } from 'tsd';

const knex = Knex(clientConfig);

const main = async () => {
expectType<User[]>(
await knex<User>('users')
.groupBy('count')
.orderBy('name', 'desc')
.havingNull('age')
);

expectType<User[]>(
await knex<User>('users')
.groupBy('count')
.orderBy('name', 'desc')
.havingNotNull('age')
);

};
7 changes: 7 additions & 0 deletions types/index.d.ts
Expand Up @@ -729,6 +729,8 @@ export declare namespace Knex {
havingNotIn: HavingRange<TRecord, TResult>;
andHavingNotIn: HavingRange<TRecord, TResult>;
orHavingNotIn: HavingRange<TRecord, TResult>;
havingNull: HavingNull<TRecord, TResult>;
havingNotNull: HavingNull<TRecord, TResult>;

// Clear
clearSelect(): QueryBuilder<
Expand Down Expand Up @@ -2007,6 +2009,11 @@ export declare namespace Knex {
>;
}

interface HavingNull<TRecord extends {} = any, TResult = unknown[]> {
(columnName: keyof TRecord): QueryBuilder<TRecord, TResult>;
(columnName: string): QueryBuilder<TRecord, TResult>;
}

// commons

interface ColumnNameQueryBuilder<
Expand Down