Skip to content

Instantly share code, notes, and snippets.

@zbinlin
Created August 6, 2019 14:22
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save zbinlin/90b5d68656f1bee2a6d24d1e868e5781 to your computer and use it in GitHub Desktop.
Save zbinlin/90b5d68656f1bee2a6d24d1e868e5781 to your computer and use it in GitHub Desktop.
async function doRequest({ type }: { type: string }, { no }: { no: number }) {
}
type Unpacked<T> = T extends Promise<infer P> ? P : T;
function wrapper<T extends (...args: any[]) => any>(fn: T) {
return async function(...args: Parameters<T>): Promise<Unpacked<ReturnType<T>>> {
return await fn.apply(null, args);
};
}
const myDoRequest = wrapper(doRequest);
myDoRequest({
type: 'foo',
}, {
no: 1,
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment