fp-ts vs native TypeScript unions: when the library is overkill
A developer revisiting their earlier post on functional programming with TypeScript argues that fp-ts, while powerful, is over-engineering for most teams not already versed in Haskell or Scala. The core problem fp-ts solves — forcing the compiler to handle failures without try/catch or loose nulls — can be addressed using TypeScript's built-in discriminated unions, which require no external imports or functional programming vocabulary. A simple tagged union with an 'ok' boolean field lets the TypeScript compiler narrow types automatically inside an if/else block, making the logic immediately readable to any developer. The hidden cost of fp-ts, the author notes, typically surfaces a few sprints in, when teammates unfamiliar with functors struggle to debug nested pipe chains and lack the vocabulary to search for help. The post stops short of ruling out fp-ts entirely, acknowledging there are scenarios — such as composing multiple failable operations — where the abstraction does earn its complexity cost.
This is an AI-generated summary. ShortSingh links to the original source for the complete article.
Discussion (0)
Log in to join the discussion and vote.
Log in