-
Notifications
You must be signed in to change notification settings - Fork 25
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
sum()
doesn't work for non-number
columns
#200
Comments
BTW, this is the workaround I'm using: import * as mammoth from '@ff00ff/mammoth';
export function sum<T extends BigInt | number | Big>(expression: Expression<T, boolean, any>): Expression<T, true, 'sum'> {
const casted = expression as Expression<number, boolean, any>;
return mammoth.sum(casted);
} Edit: fixed return value from |
I think there should be a So something like |
Somewhat related: I think Mammoth must make a distinction between int8 and int4 in the public interface. In the case of |
Hmm I thought I had a fix but it's not working properly yet. |
In my Mammoth schema definition, I'm using
big.js
for Postgresnumeric
and JSBigInt
for Postgresint8
.The Mammoth
sum
function doesn't work on those types:The quick fix for me is to define my own
sum
function with a different type. That's what I'm going to do for now.But I wonder if there's a more general solution. One option would be to add a new "IsSummable" type parameter to the
Expression
type. But another type parameter ends up adding a bunch of noise to the IDE auto-complete and error messages.I think Scala "type members" (called "associated types" in Rust and Swift) might provide a cleaner solution, but I'm not sure if that's possible in TypeScript. Here's one attempt to simulate them in TypeScript: StackOverflow link.
The text was updated successfully, but these errors were encountered: