Skip to content

Commit

Permalink
Add Date as a valid return type for max and min (#1062)
Browse files Browse the repository at this point in the history
  • Loading branch information
samclearman authored and igalklebanov committed Jan 9, 2025
1 parent 1a41856 commit 0d15b04
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 7 deletions.
18 changes: 14 additions & 4 deletions src/query-builder/function-module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -487,15 +487,20 @@ export interface FunctionModule<DB, TB extends keyof DB> {
* ```
*/
max<
O extends number | string | bigint | null = never,
O extends number | string | Date | bigint | null = never,
RE extends ReferenceExpression<DB, TB> = ReferenceExpression<DB, TB>,
>(
expr: RE,
): AggregateFunctionBuilder<
DB,
TB,
IsNever<O> extends true
? ExtractTypeFromReferenceExpression<DB, TB, RE, number | string | bigint>
? ExtractTypeFromReferenceExpression<
DB,
TB,
RE,
number | string | Date | bigint
>
: O
>

Expand Down Expand Up @@ -538,15 +543,20 @@ export interface FunctionModule<DB, TB extends keyof DB> {
* ```
*/
min<
O extends number | string | bigint | null = never,
O extends number | string | Date | bigint | null = never,
RE extends ReferenceExpression<DB, TB> = ReferenceExpression<DB, TB>,
>(
expr: RE,
): AggregateFunctionBuilder<
DB,
TB,
IsNever<O> extends true
? ExtractTypeFromReferenceExpression<DB, TB, RE, number | string | bigint>
? ExtractTypeFromReferenceExpression<
DB,
TB,
RE,
number | string | Date | bigint
>
: O
>

Expand Down
1 change: 0 additions & 1 deletion test/node/src/test-setup.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@ import {
InsertResult,
SqliteDialect,
InsertQueryBuilder,
Logger,
Generated,
sql,
ColumnType,
Expand Down
4 changes: 2 additions & 2 deletions test/typings/test-d/aggregate-function.test-d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -339,13 +339,13 @@ async function testSelectWithDynamicReference(db: Kysely<Database>) {
expectNotAssignable<null>(result.count)
expectAssignable<bigint>(result.another_count)
expectNotAssignable<string | number | null>(result.another_count)
expectAssignable<string | number | bigint>(result.max)
expectAssignable<number | string | Date | bigint>(result.max)
expectNotAssignable<null>(result.max)
expectAssignable<number>(result.another_max)
expectNotAssignable<string | bigint>(result.another_max)
expectAssignable<number | null>(result.nullable_max)
expectNotAssignable<string | bigint>(result.nullable_max)
expectAssignable<string | number | bigint>(result.min)
expectAssignable<number | string | Date | bigint>(result.min)
expectNotAssignable<null>(result.min)
expectAssignable<string>(result.another_min)
expectNotAssignable<number | bigint | null>(result.another_min)
Expand Down

0 comments on commit 0d15b04

Please sign in to comment.