I'm very new to typescript and I wanted to try and reduce my usage of try...catch blocks by creating a one liner method. the issue that I have is that I don't know how to infer or create a correct return type that my VS code intenseness recognizes the result value.
I was initially trying to get it to work using generic types but I don't think that's the correct approach.
// My try catch block
async function solve<T>(fn: T) {
const res = await fn;
if(res)
return [res, false];
return [null, true];
}
(async ()=>{
const [a, b] = await solve(new Promise(resolve => {
setTimeout(()=>{
resolve({
n: 1
})
}, 2000)
}));
// I want to get suggestion that "n" is a property of returned "a".
console.log(a)
// this gives typescript error
console.log(a.n)
})();