rethinkdb-ts icon indicating copy to clipboard operation
rethinkdb-ts copied to clipboard

The type signature of `getAll()` does not permit more than 4 document keys.

Open vxern opened this issue 9 months ago • 2 comments

Describe the bug The method is typed as accepting only 1-4 document keys, which is incorrect, given that it is generated from this specification:

[TermType.GET_ALL, 'getAll', 0, -1, 'optional']

Where I understand that -1 represents the fact that the method can take an indefinite number of arguments, which means it should support an indefinite number of document keys.

Expected behavior It should be possible to get any arbitrary number of keys using the method, not only four at max.

vxern avatar May 02 '24 19:05 vxern

The problem is that we can't do that properly in typescript without changing an order of the arguments for the getAll, which is a breaking change. Several years ago I was thinking about making a shim for this with inverted arguments, or with providing ids as arguments. And, as you understand, got to no conclusion. I'll think about it, still, you are free to make any suggestions, I'll see them through

atassis avatar May 04 '24 00:05 atassis

I think having the keys passable as an array is a neat solution, like so:

getAll<T>(table: RTable<T>, keys: any[], options?: { index: string; }): RSelection<T>;

I'm not too familiar with the underlying package code and how the package could deal with the keys argument being an array, but couldn't another overload such as this one be added without any breaking change? I would assume that a key (key1, key2, etc.) cannot (or at least is not expected) to be an array, even if the type is currently any, but I would leave a person more familiar with the codebase such as yourself to answer that.

Another solution could be to leverage TypeScript's variadic tuple type signatures, where TypeScript would ensure that the type of the last parameter met the spec for what the indexes parameter should look like.

vxern avatar May 04 '24 11:05 vxern