From c748f39b45333d259171e28f1a1cc3fdb2f91ee0 Mon Sep 17 00:00:00 2001 From: mrichards42 Date: Tue, 9 Aug 2022 13:47:39 -0400 Subject: [PATCH] Infer specific column value type in aggregations The first overload of TypePreservingAggregation (taking columnName and options) used `Readonly` for the columnName type. In this context, `TKey` is supposed to be a single column name, but `Readonly` maps over the full constraint of `ResolveTableType`. 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. --- types/index.d.ts | 2 +- types/test.ts | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/types/index.d.ts b/types/index.d.ts index e4423dbbbd..4f2d25587c 100644 --- a/types/index.d.ts +++ b/types/index.d.ts @@ -1864,7 +1864,7 @@ export declare namespace Knex { } > >( - columnName: Readonly, + columnName: TKey, options: Readonly ): QueryBuilder; < diff --git a/types/test.ts b/types/test.ts index 5a25ce76f6..b7347fa18f 100644 --- a/types/test.ts +++ b/types/test.ts @@ -1197,7 +1197,7 @@ const main = async () => { // $ExpectType Dict await knexInstance.first().min('age').from('users'); - // $ExpectType ({ a: string | Date; } & { b: string | Date; })[] + // $ExpectType ({ a: Date; } & { b: Date; })[] await knexInstance('tickets') .min('at', {as: 'a'}) .max('at', {as: 'b'});