I'm trying to create a wrapper around an async function, when I call the function I always get a function instead of the object I want to get.
function wrap<T extends Function>(fn: T){
return <any> async function (...args) {
let result = await fn(...args)
return {
statusCode: 200,
body: JSON.stringify({
data: result
}),
}
};
}
let main = async (test: string) => {
console.log(`calling api ${test}`);
return wrap(() => {
console.log("")
return {
foo: "bar",
}
});
};
main("test").then((res)=>{
console.log(res)
console.log(typeof res) // <-- function
})
What I'm missing ?
Any help will be appreciated.