TypeScript's Built-In Discriminated Unions Can Replace fp-ts Either for Most Teams
A DEV Community article argues that fp-ts, a popular functional programming library for TypeScript, is overkill for most development teams without a Haskell or Scala background. The author contends that TypeScript's native discriminated unions already solve the core problem fp-ts addresses — handling errors without exceptions or loose nulls — without requiring any external library. Using a shared literal field like 'ok', the compiler can narrow types inside a simple if-else block, making the code immediately readable to any developer familiar with basic TypeScript. The hidden cost of fp-ts, the author warns, typically surfaces several sprints later when team members unfamiliar with functional concepts struggle to debug complex pipe-and-chain compositions. The piece stops short of dismissing fp-ts entirely, acknowledging it remains justified when composing multiple async operations or building pipelines where the abstraction genuinely pays off.
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