News for hackers. Stuff that matters.
Re:JavaScript best practice: use return await by pestatije on Friday March 07, 2025 @02:37PM (#43293605)
if you await for an async to return then why do you use async in the first place?
Re:JavaScript best practice: use return await by mdc2161 on Friday March 07, 2025 @03:23PM (#43294138)
If the inner function is async, then its callers need to be async as well (see https://journal.stuffwithstuff.com/2015/02/01/what-color-is-...).

Important to note that unless the inner function throws an exception, the two versions are essentially identical, even sharing (if using typescript) a return type definition of `Promise<ReturnType<InnerFunction>>`.

That's because `await` flattens nested promises, so both `Awaited<Promise<T>>` and `Awaited<Promise<Promise<Promise<T>>>>` resolve to `T`.