Functions that take `anyreal` numeric type as arguments and return `anyreal` do not narrow based on the arguments
Code
// Inferred type: string | number | bigint
// Expected: bigint
const max = await e.max(e.set(1n, 2n)).run(client);
Versions (please complete the following information):
- OS:
- EdgeDB version (e.g.
2.0):2.14+7aec755 - EdgeDB CLI version (e.g.
2.0):2.3.1+ef99779 edgedb-jsversion (e.g.0.20.10;):1.2.1@edgedb/generateversion (e.g.0.0.7;):0.1.0- Typescript version:
4.9.5 - Node/Deno version:
18.12.1
I agree that we can add some additional overloads to get a more useful narrowed type, thanks for reporting!
Ahh, it looks like this comes straight out of how the max function is defined in EdgeQL: https://github.com/edgedb/edgedb/blob/8f6ae3109d033534f94e6af21a140dd2cb55b375/edb/lib/std/20-genericfuncs.edgeql#L346-L354
It is of type anyreal and the decimal type is actually a string. It doesn't look like we currently do any kind of special-casing in our generator code to generate more overloads than the description that the database returns, so I'm loathe to start making special cases just yet, but I'll discuss with the team and see about maybe changing the underlying representation of that function so we can stay generic in our reflection code. If it seems not likely that we'll update the underlying schema description, I'll explore how best to make a maintainable mechanism to expand anyreal returning functions to be more narrow in general.