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鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

Infer specific column value type in aggregations #5297

Merged
merged 1 commit into from Aug 28, 2022

Conversation

mrichards42
Copy link
Contributor

馃憢 Hi folks, thanks for a great library! I came across what looks like a typing bug to me:


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 keyof 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.

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.
@coveralls
Copy link

Coverage Status

Coverage remained the same at 92.27% when pulling c748f39 on mrichards42:fix-aggregation-type into 2dadde4 on knex:master.

@OlivierCavadenti OlivierCavadenti merged commit 57692d3 into knex:master Aug 28, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants