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

e.op complains about invalid overload when at runtime it works fine

Open Gobot1234 opened this issue 1 year ago • 5 comments

Code The code causing the error.

e.insert(e.User, () => ({
  ucard_number: e.op(
	// atomically decrement this field for new inserts where we don't have it
	// to preserves the uniqueness.
	e.min(
	  e.set(
	    e.assert_single(
	      e.select(e.users.User, (user) => ({
	        order_by: {
	          expression: user.ucard_number,
	          direction: e.ASC,
	          limit: 1,
	        },
	      })),
	    ).ucard_number,
	    -1,
	  ),
	),
    '-',
	1,
  ),
})

Schema

Your application schema.

module default {
type User {
    ucard_number: int32 {
        constraint exclusive;
    }
}

Generated EdgeQL

The generated EdgeQL works fine the

Error or desired behavior

No overload matches this call.
  The last overload gave the following error.
    Argument of type 'minλFuncExpr<$expr_Set<TypeSet<ScalarType<"std::number", number, number, number>, Cardinality.AtLeastOne>>>' is not assignable to parameter of type 'orScalarLiteral<TypeSet<$str, Cardinality>>'.
      Type 'minλFuncExpr<$expr_Set<TypeSet<ScalarType<"std::number", number, number, number>, Cardinality.AtLeastOne>>>' is not assignable to type 'TypeSet<$str, Cardinality>'.
        Types of property '__element__' are incompatible.
          Type '$anyreal' is not assignable to type '$str'.
            Type '$number' is not assignable to type 'ScalarType<"std::str", string, string, string>'.
              Type '"std::number"' is not assignable to type '"std::str"'.ts(2769)
operators.ts(4463, 10): The last overload is declared here.
operators.ts(4471, 10): The call would have succeeded against this implementation, but implementation signatures of overloads are not externally visible.

Versions (please complete the following information):

  • OS: macOs
  • EdgeDB version (e.g. 2.0): 4.3+d0acb4e
  • EdgeDB CLI version (e.g. 2.0): EdgeDB CLI 4.1.0-dev.1070+acd4979
  • edgedb-js version (e.g. 0.20.10;): [email protected]
  • @edgedb/generate version (e.g. 0.0.7;): v0.4.1
  • Typescript version: Version 4.5.5
  • Node/Deno version: v21.5.0

Gobot1234 avatar Jan 12 '24 17:01 Gobot1234

Thanks for the report! This seems to be an issue were the function expression type is not assignable to our e.op overloads. Will fix!

scotttrinh avatar Jan 12 '24 17:01 scotttrinh

I'm new to edgedb, and I've been trying to increment a field for the last hour thinking I was doing something wrong :joy: Thanks for opening this issue.

Can someone confirm that the following should work ? If so, I'll wait for this to be fixed and work on something else in the meantime. (I wouldn't want to look like a fool and wait for "nothing", hehe)

const userSeq = "<UUID>"
const seqInt = await e
        .update(e.Sequences, (seq) => ({
            filter: e.op(seq.id, "=", userSeq.id),
            set: {
              counter: e.op(seq.counter, '+', 1)
            }
        })).run(client);

Extarys avatar Jan 12 '24 20:01 Extarys

@Extarys I think you might have a separate issue, can you open a separate issue and post any errors or issues you're having there? Or join us on Discord and we can help troubleshoot in realtime.

scotttrinh avatar Jan 12 '24 22:01 scotttrinh

@scotttrinh Thanks! It wasn't my intention to confuse this issue. With a fresh mind, I found my mistake. filter: e.op(seq.id, "=", e.cast(e.uuid, userSeq.id)),, I needed to cast the uuid as such ;) Eventually, down the line, those types of errors could be a bit more verbose ;)

Extarys avatar Jan 13 '24 16:01 Extarys

@Gobot1234

Just a heads up that wrapping an e.cast around e.min seems to work in the meantime. Still need to fix the overload behavior here, but wanted to hit you with a usable workaround that was found by another user while you're waiting for this fix here.

scotttrinh avatar Feb 08 '24 17:02 scotttrinh