Hacker News new | ask | show | jobs
by koblas 1757 days ago
Interesting that the author used joi as the example, when the io-ts validation library fully embraces the functional world with success/fail return value from validation. Realistically, the advantage throw has is that if you have a single error handler in a function it avoids the "go" problem of tons of lines of error handling. The other side is that error handling becomes "optional".
1 comments

Personally, I gave up on io-ts due to FP complications, and use suretype instead.

In my case, where I was parsing HTTP request body, it just simplifies the code, if I can call a single function, get back validated object of the expected type, or throw an exception if there is a problem.

Global request handler takes care of catching validation exception, and returning back user friendly error on what field(s) failed validation.

suretype looks interesting, will have to do a bit of review there. One of the things we're now doing is using io-ts for both encoding and decoding types. Internally we're more JSON than gRPC so we're using it to provide a standardized way to move data between components.