I have the following code :
function builder<T extends Foo>(
getItems: (...) => Promise<T[]>, /* unsure what to put between parenthesis here */
) {
return async (...): Promise<Baz> => {
const items = await getItems(...); /* unsure what to put between parenthesis here */
// some manipulation here
return items;
}
My goal is to allow the builder function to accept an asynchronous callback. This callback can be called with various types of parameters. There could be one, or many parameters inside the callback.
For example, I could call the builder function such as :
// call 1
builder<SomeResult>((a, b) => someCallback(a, b));
// call 2
builder<AnotherResult>((c) => otherCallback(c));
I'm pretty new to typescript so not quite sure how to do this. I think maybe i should look into rest arguments but not exactly sure how to tackle the problem.
Any help would be much appreciated. Thanks a lot for the tips.
builderi just want to be able to callgetItemswith whatever arguments were passed via the callback.getItemswith, so how wouldbuilderknow what to pass?getItemsis the callback function. I wantbuilderto pass whatever arguments I have specified when defining my callback (a, b, or c). With your answer, you've got me doubting that this is even possible, but I would have thought so. XDreturn async (...): Promise<Baz> => {.