Hacker News new | ask | show | jobs
by Prosammer 856 days ago
Yes, I'm stoked you brought this up, as I had previously googled and found some articles that recommend doing this in typescript. I haven't tried it out yet though, mainly because it seems like every article has a different approach to production-ready error handling in typescript and I don't know the best approach. Do you / does anyone have any suggestions for articles etc. on this?
1 comments

no I would just do what makes sense to me, which is what I commented. you can do exceptions or type the return values. sounds like you want to do the latter. handling it isn't as nice as in rust though, I agree. You could create a simple object to emulate it though like "ReturnValue { unwrap: fn, ifOk: fn, ifErr: fn } " where unwrap throws if invalid, ifOk returns true if the response is valid, and ifErr returns true if an err.
Cheers!