Created
August 6, 2019 14:22
-
-
Save zbinlin/90b5d68656f1bee2a6d24d1e868e5781 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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