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

Justin Walsh pfp
Justin Walsh
@thejustinwalsh.eth
Came here to say the same thing. I find it super clean to use something like https://github.com/scopsy/await-to-js, and deal with error cases up front. Shakes that happy path programmer stigma right off.
0 reply
0 recast
1 reaction