Would greatly appreciate any assistance with adding types to the following JavaScript function in TypeScript. I've been trying to solve this without resorting to using 'any' for an entire day with no luck.
Here's the JavaScript function:
function executeAll(...funcs) {
const result = funcs.reduce((currentResult, nextFunc) => {
return {
...currentResult,
...nextFunc(),
};
}, {});
return result;
}
Here's an example of how to use it:
const result = executeAll(
() => { return { firstResult: "Abc" } },
() => { return { secondResult: 123 } });
console.log(result);
The function in the example creates an object like this: { firstResult: "Abc", secondResult: 123 }
Essentially, the result of "executeAll" should be a union of the return values of each function passed in. Is this even possible, or am I attempting something that cannot be achieved?
Any guidance would be highly appreciated.
Thank you,
Miro