edgedb / edgedb-js

The official TypeScript/JS client library and query builder for EdgeDB
https://edgedb.com
Apache License 2.0
509 stars 62 forks source link

No overload matches this call #726

Closed sharifzadesina closed 9 months ago

sharifzadesina commented 10 months ago

Code

The code causing the error.

import * as edgedb from "edgedb";
import e from "../dbschema/edgeql-js";

const client = edgedb.createClient();

async function main() {
  // result will be inferred based on the query
  const result = await e.select(e.Movie, () => ({
    title: true,
    actors: () => ({ name: true }),
    filter_single: { title: 'Iron Man 2' }
  })).run(client);

  console.log(JSON.stringify(result, null, 2));
}

main();

Schema

Your application schema.

module default {
  type Person {
    required name: str;
  }

  type Movie {
    required title: str;
    multi actors: Person;
  }
}

Generated EdgeQL

Run the .toEdgeQL() method on your query and print the result. Then copy the generated query here.

There is no need for this since it is a type error.

Error or desired behavior

Copy/paste the error, or drag/drop a screenshot displaying the error message. If there's no error, describe the expected behavior.

No overload matches this call.
  Overload 1 of 6, '(expr: $expr_PathNode<TypeSet<$Movie, Cardinality.Many>, null>, shape: (scope: { __element__: $Movie; __cardinality__: Cardinality.One; __parent__: PathParent<...> | null; __kind__: ExpressionKind.PathNode; "*": { ...; }; } & { ...; } & {} & ExpressionMethods<...> & { ...; }) => Readonly<...>): $expr_Select<...>', gave the following error.
    Type '{ title: string; }' is not assignable to type 'SelectFilterExpression | { id: orLiteralValue<{ __element__: $uuid; __cardinality__: Cardinality.AtMostOne | Cardinality.One; }>; } | undefined'.
      Object literal may only specify known properties, and 'title' does not exist in type 'SelectFilterExpression | { id: orLiteralValue<{ __element__: $uuid; __cardinality__: Cardinality.AtMostOne | Cardinality.One; }>; }'.
  Overload 2 of 6, '(expr: PrimitiveTypeSet, modifiers: (expr: PrimitiveTypeSet) => Readonly<SelectModifiers<ObjectType<string, ObjectTypePointers, any, ExclusiveTuple>>>): $expr_Select<...>', gave the following error.
    Argument of type '$expr_PathNode<TypeSet<$Movie, Cardinality.Many>, null>' is not assignable to parameter of type 'PrimitiveTypeSet'.
      Types of property '__element__' are incompatible.
        Type '$Movie' is not assignable to type 'PrimitiveType'.
          Type 'ObjectType<"default::Movie", { id: PropertyDesc<$uuid, Cardinality.One, true, false, true, true>; __type__: LinkDesc<$ObjectType, Cardinality.One, ... 4 more ..., false>; title: PropertyDesc<...>; actors: LinkDesc<...>; }, null, [...]>' is not assignable to type 'ScalarType<string, any, any, any> | EnumType<string, [string, ...string[]]> | TupleType<BaseTypeTuple> | NamedTupleType<NamedTupleShape>'.
            Type 'ObjectType<"default::Movie", { id: PropertyDesc<$uuid, Cardinality.One, true, false, true, true>; __type__: LinkDesc<$ObjectType, Cardinality.One, ... 4 more ..., false>; title: PropertyDesc<...>; actors: LinkDesc<...>; }, null, [...]>' is not assignable to type 'NamedTupleType<NamedTupleShape>'.
              Types of property '__kind__' are incompatible.
                Type 'TypeKind.object' is not assignable to type 'TypeKind.namedtuple'.ts(2769)
select.ts(119, 3): The expected type comes from property 'filter_single' which is declared here on type 'Readonly<Partial<{ id: boolean | $expr_PolyShapeElement | TypeSet<$uuid, Cardinality.One>; __type__: linkDescToSelectElement<LinkDesc<$ObjectType, ... 5 more ..., false>>; title: boolean | ... 1 more ... | TypeSet<...>; actors: linkDescToSelectElement<...>; }> & { ...; } & SelectModifiers<...>>'

Versions (please complete the following information):

sharifzadesina commented 9 months ago

It seems the filter_single only works with constraint exclusive; properties, so if a property doesn't have constraint exclusive; it won't work with filter_single, closing the issue since it was my bad to forget about adding constraint exclusive; to title property.