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 1 commit
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
8 changes: 8 additions & 0 deletions types/index.d.ts
Expand Up @@ -729,6 +729,9 @@ 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 +2010,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
12 changes: 12 additions & 0 deletions types/test.ts
Expand Up @@ -891,6 +891,18 @@ const main = async () => {
.orderBy('name', 'desc')
.havingRaw('age > ?', [10]);

// $ExpectType User[]
await knexInstance<User>('users')
.groupBy('count')
.orderBy('name', 'desc')
.havingNull('age');

// $ExpectType User[]
await knexInstance<User>('users')
.groupBy('count')
.orderBy('name', 'desc')
.havingNotNull('age');

// $ExpectType User[]
await knexInstance<User>('users')
.select()
Expand Down