I am struggling with the code below:
function builder<T extends Foo>(
getItems: (...) => Promise<T[]>, /* uncertain about what to include in the parentheses here */
) {
return async (...): Promise<Baz> => {
const items = await getItems(...); /* not sure what parameters should go between the parentheses here */
// some manipulation here
return items;
}
My objective is to enable the builder
function to accept an asynchronous callback that can handle different types of parameters. This callback could have one or multiple parameters passed into it.
For instance, I might use the builder
function like this:
// call 1
builder<SomeResult>((a, b) => someCallback(a, b));
// call 2
builder<AnotherResult>((c) => otherCallback(c));
Being new to TypeScript, I am unsure of how to achieve this. I believe exploring rest arguments might help, but I am unclear on how to approach the issue.
Any guidance on this matter would be greatly appreciated. Thank you for any assistance provided.