edgedb / edgedb-js

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

Use `queryRequired` for `AtLeastOne` cardinality #1074

Closed scotttrinh closed 3 months ago

scotttrinh commented 3 months ago

Fixes a TypeScript error where query was returning T[] but the return type of the function as [T, ...T[]] and TypeScript was rightly complaining that they are incompatible.

Fixes #1072

CarsonF commented 3 months ago

Don't we know the number of items in the tuple? and their types. Why don't we strictly enumerate those in the generated TS?

select { "a", "b", "c" }
const result: [string, string, string] = await
result[1] // string
result[4] // error / undefined
scotttrinh commented 3 months ago

Don't we know the number of items in the tuple?

We do in a tuple, but this is a set, not a tuple. All we know is the type and cardinality.

Querying for a tuple already does the right thing of returning either a tuple type (for tuples) or an object (for named tuples).

CarsonF commented 3 months ago

Ah of course 👍