3 ms·
Typescript has no problem with typing your scenario (or at least nothing that isn’t present in “plain” JavaScript… what if your value is a promise?) And compil
by rtpg 2y ago
Typescript has no problem with typing your scenario (or at least nothing that isn’t present in “plain” JavaScript… what if your value is a promise?)
And compiled languages don’t have more trouble with this than JavaScript. Or rather, Javascript doesn’t have less issues on this front. The color issue is an issue at the syntactic level!
- timewizard 2y agoExcept you can await on non-Promise objects which just returns the original object. Most other typed languages do not appear have this convenience. C# (the apparent source of the color rant) does not. It sets JavaScript apart. Likewise Promise.resolve() on a promise object just returns the original promise. You can color and uncolor things with far less effort or knowledge of the actual type.
- deleted 2y ago[deleted]
- jakelazaroff 2y agoAwaiting a non-promise doesn’t make it synchronous, though — it still executes any subsequent lines in a microtask. Try running this code. It’ll print “bar” first and then “foo”, even though the function only awaits a string literal and the caller doesn’t await anything at all. const foo = async () => console.log(await "foo"); foo(); console.log("bar");
- neonsunset 2y agoIn C# nothing stops you from doing `var t = Task.Run(() => ExpensiveButSynchronous());` and then `await`ing it later. Not that uncommon for firing off known long operations to have some other threadpool thread deal with it. Unless you literally mean awaiting non-awaitable type which...just doesn't make sense in any statically typed language?
- dang 2y agoPlease see https://news.ycombinator.com/item?id=44026655 https://news.ycombinator.com/item?id=44026655.