I'd like to design a library that wraps any async function. The wrapped async function can have multiple args
If I do
type AsyncFunction<I, O> = (inputs: I) => Promise<O>;
function wrapper<I, O>(
asyncFunction: AsyncFunction<I, O>,
): AsyncFunction<I, O> { ... }
The typing of T will only apply to the first arg so this makes my wrapper unusable with any async function that takes multiple parameters.
Can someone give me a solution to support multiple args?
Edit
This is where I am currently:
type AsyncFunction<I extends any[], O> = (...inputs: I) => Promise<O>;
export function onlyResolvesLast<I extends any[], O>(
asyncFunction: AsyncFunction<I, O>,
): AsyncFunction<I, O> {
let cancelPrevious;
return function wrappedAsyncFunction(...args) {
cancelPrevious && cancelPrevious();
const initialPromise = asyncFunction(...args);
const { promise, cancel } = createImperativePromise(initialPromise);
cancelPrevious = cancel;
return promise;
};
}

