Errors-as-values is one of the better ideas to reach mainstream TypeScript. Instead of throwing an exception that the type system can't see, a function returns a Result<T, E> and failure becomes part of the type. neverthrow, boxed, byethrow, and effect all give you some version of it, and if you've adopted one you already know why it's worth it.
But most of them stop one step short, and that step is where a specific class of bug lives: the kind that looks like a domain error but isn't. This post is about that gap, why it matters, and how a small library called
Docs: https://btravstack.github.io/unthrown/
pnpm add unthrownOrdinary errors are unthrown: returned as values, not flung up the stack. Only a true defect ever throws, and only at unwrap.
If this resonated, a ❤️ or 🦄 helps it reach other people fighting the same catch (e: unknown) battle. What does your team do about the gap between domain errors and genuine bugs? Curious to hear it in the comments.
SOCIAL SHARE CARD GENERATOR