5 ms·
I agree with your point. On > Anything with a `then` method can be awaited, and so native Promises aren’t actually all the special or sacred. Invoking await on
by kitten_mittens_ 3y ago
I agree with your point. On
> Anything with a `then` method can be awaited, and so native Promises aren’t actually all the special or sacred. Invoking await on an expression involves no extra machinery, only that a Promise-like object is returned.
note that _anything_ can be awaited in JS.
```
const x = await null;
console.log(x)
```
- TeffenEllis 3y agoHuh wow! I did not know that! I think TypeScript always kept this hidden from me, but it makes sense. Another perk of `await` is that it collapses all promises into their final value, regardless of how many nested pending promises are expressed: const foo = await Promise.resolve(Promise.resolve("abc")) console.log(foo.length) // 3
- bakkoting 3y agoIt's not `await` which is doing that; it's the Promises themselves. For example: Promise.resolve(Promise.resolve("abc")).then(console.log) This will print `"abc"`, not `Promise.resolve("abc")`.