edgedb-js icon indicating copy to clipboard operation
edgedb-js copied to clipboard

Functions that take `anyreal` numeric type as arguments and return `anyreal` do not narrow based on the arguments

Open hbriese opened this issue 2 years ago • 2 comments

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-js version (e.g. 0.20.10;): 1.2.1
  • @edgedb/generate version (e.g. 0.0.7;): 0.1.0
  • Typescript version: 4.9.5
  • Node/Deno version: 18.12.1

hbriese avatar May 09 '23 11:05 hbriese

I agree that we can add some additional overloads to get a more useful narrowed type, thanks for reporting!

scotttrinh avatar May 09 '23 13:05 scotttrinh

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.

scotttrinh avatar May 09 '23 14:05 scotttrinh