When it comes to handling promises in TypeScript, I'm used to the then
/catch
style like this:
.findById(id)
.then((result: something | undefined) => result ?? dosomething(result))
.catch((error: any) => console.log(error))
However, I have also come across a pattern where void is utilized to prevent floating promises, and sometimes my language server even suggests it as a solution.
void somePromise().dosomething();
As someone not well-versed in TypeScript or promises, I find myself questioning why one would choose to skip using catch and opt for void instead. My brief search on Google didn't provide a clear answer on when each approach should be taken.
I found this explanation of what void does, but it doesn't explain the reasoning behind choosing void over catch. While there are discussions on how to solve floating promises, none that I could find delve into the rationale for preferring void over catch.