Content pfp
Content
@
0 reply
0 recast
0 reaction

jxom  pfp
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 πŸ”΅ pfp
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 pfp
YuriNondual
@yurinondual
well the second one, unless you actually need to check response status before doing .json()? πŸ€”
0 reply
0 recast
0 reaction

Danny pfp
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://ウエハ pfp
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 pfp
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 pfp
cdt
@cdt
clean 🧼
0 reply
0 recast
0 reaction