Skip to content

Commit

Permalink
Infer specific column value type in aggregations (#5297)
Browse files Browse the repository at this point in the history
The first overload of TypePreservingAggregation (taking columnName and
options) used `Readonly<TKey>` for the columnName type. In this context,
`TKey` is supposed to be a single column name, but `Readonly<TKey>` maps
over the full constraint of `ResolveTableType<TRecord>`.

This results in `TKey` being a union of all keys in the table, rather
than a single key. Because of this, the result type ends up being a
union of all values in the table.

The fix is to remove the `Readonly` type, which is fine since `TKey` is
a string and not an object like in the other overloads.
  • Loading branch information
mrichards42 committed Aug 28, 2022
1 parent 579ab4b commit 57692d3
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 2 deletions.
2 changes: 1 addition & 1 deletion types/index.d.ts
Expand Up @@ -1864,7 +1864,7 @@ export declare namespace Knex {
}
>
>(
columnName: Readonly<TKey>,
columnName: TKey,
options: Readonly<TOptions>
): QueryBuilder<TRecord, TResult2>;
<
Expand Down
2 changes: 1 addition & 1 deletion types/test.ts
Expand Up @@ -1197,7 +1197,7 @@ const main = async () => {
// $ExpectType Dict<any>
await knexInstance.first().min('age').from<User>('users');

// $ExpectType ({ a: string | Date; } & { b: string | Date; })[]
// $ExpectType ({ a: Date; } & { b: Date; })[]
await knexInstance<Ticket>('tickets')
.min('at', {as: 'a'})
.max('at', {as: 'b'});
Expand Down

0 comments on commit 57692d3

Please sign in to comment.