DataLoader is a generic utility to be used as part of your application's data fetching layer to provide a consistent API over various backends and reduce requests to those backends via batching and caching.
const loadResults = (): Promise<Array<Result | Error>> => {
const [a, b] = loader.loadMany(["1", "2"]);
// TypeError: "a" and "b" can both be undefined
if (a.prop === b.prop) {
return [a];
}
return [a, b];
}
In the above code, both a and b can be undefined because the ArrayLike type does not guarantee the presence of any element; basically, loadMany could still be an empty array (based on the type). However, based on the logic implemented in this library, I believe the number of results will always match the number of keys in the input. Hence, the use of tuples makes more sense, in my opinion.
Closing this, my mistake. I thought variadic tuple types could express the relationship between the cardinality of arguments and the return type in a generic way but they can't 🙁
Assume the following code:
In the above code, both
a
andb
can beundefined
because theArrayLike
type does not guarantee the presence of any element; basically,loadMany
could still be an empty array (based on the type). However, based on the logic implemented in this library, I believe the number of results will always match the number of keys in the input. Hence, the use of tuples makes more sense, in my opinion.What do you think?