Content
@
0 reply
0 recast
0 reaction
jxom
@jxom
A couple of JavaScript tricks using promise syntax: 1. We can transform a try/catch block into a one-liner (also means `result` return type is inferred properly), 2. We can transform a `fetch` β `.json` chain into a one-liner `.then` and `.catch` are still cool (sometimes)!
7 replies
0 recast
16 reactions
typeof.eth π΅
@typeof.eth
If you wanna avoid try/catch and are feeling a lil π¦y, you can write a util to turn the data/error into a tuple. You can squeeze some really good type inference out of it too. E.g.
1 reply
0 recast
1 reaction
YuriNondual
@yurinondual
well the second one, unless you actually need to check response status before doing .json()? π€
0 reply
0 recast
0 reaction
Danny
@ds
Agree! Promises are almost monadic, might as well use the good parts. I do wish result and maybe types were native.
0 reply
0 recast
0 reaction
netop://γ¦γ¨γ
@netopwibby.eth
I'm so used to try/catch that I never think about then/catch
0 reply
0 recast
0 reaction
Thiago Brezinski
@thiagobrez
Love this, and can not understand people that only use one or the other like a cult
0 reply
0 recast
0 reaction
cdt
@cdt
clean π§Ό
0 reply
0 recast
0 reaction