5 ms·
> I do wish that Typescript would offer some tools to make it more ergonomic to write performant unifying code (I kind of despise conditional types Maybe give
by vmfunction 2y ago
> I do wish that Typescript would offer some tools to make it more ergonomic to write performant unifying code (I kind of despise conditional types
Maybe give https://gcanti.github.io/fp-ts/ https://gcanti.github.io/fp-ts/ a go?
- rtpg 2y agoI use fp.ts quite a lot! I think it's _extremely unfortunate_ that the API docs don't include top-level examples for basically anything, though. So when people hit a problem that fp-ts or io-ts can solve, I have to basically write a disclaimer about the slight impenetrability before suggesting it. I really think that TS itself should offer syntax more or less matching what that lib does at the type level, but this is a bit of a maximalist request.
- epolanski 2y agoeffect-ts is nowadays the de facto successor of fp-ts and has better docs. As for fp-ts all APIs have examples/tests that show their usage.
- chrisweekly 2y agoThanks for the effect-ts suggestion! Looks pretty compelling...
- shepherdjerred 2y agoIMO Zod is much easier to understand than io-ts, the counterpart to fp-ts: https://zod.dev/ https://zod.dev/
- eyelidlessness 2y agoIt’s been a while since I looked deeply at them, but IIRC the primary difference is that io-ts returns Result types. It’s trivial to wrap that to produce a value or throw if that feels more comfortable. It’s possible there are other aspects of the APIs that differ in meaningful ways, but last I checked virtually all of the libraries with similar functionality (and there are many) have roughly the same concepts until your schemas themselves get deeply complex.
- zarzavat 2y agoZod can also return result types: T.safeParse(x) It’s not a very full featured Result, but you can wrap it with your own type.