Re:TypeScript 3.7
by yawaramin on Tuesday November 05, 2019 @09:19PM
(#21459094)
IIFEs are an option:
[ Parent
| on HN ]
I don't think this is correct, as the try catch will only catch errors that happen while returning the promise, not awaiting it; you need to do this:
const result = await (async () => {
try {
return await funcThatReturnSomeType();
} catch (err) {
doSomethingWithErr(err);
}
})();You may be right, proving the old adage that the best way to get an answer on the internet is to post a wrong answer ;-)
Iffys are a nice go-to in ts in general, because type inference is so handy and I'd rather not have a big pile of typed `let`s at the top that I have to assign into later. Even something as simple as a switch plays nicer if you iffy it and use it like an expression (similar to a match is rust)