|
|
|
|
|
by shtylman
2419 days ago
|
|
Can you hoist the `if (result)` into the `try` part of the statement? (Without seeing more context hard to know why that wouldn't work for you). Another pattern to avoid the above is to remember that async functions return promises and that .catch() also returns a promise. So your above logic can be written as: const result = await funcThatReturnSomeType().catch(doSomethingWithErr);
if (result) {
doSomething(result);
}
|
|