Ts-result – Rust's Result<T, E> type for explicit error handling in TS
Ts-result – Rust's Result<T, E> type for explicit error handling in TS
Hey HN, Like many, I've often found standard error handling in JS/TS (heavy try-catch, ambiguous null returns) a bit cumbersome for representing expected failures explicitly. Inspired by Rust's Result<T, E> enum (Ok(T) | Err(E)), we built ts-result. It's a lightweight, focused TypeScript library bringing that pattern over: Explicit Result<T, E> return types for functions. Type safety via discriminated unions and type guards (isOk/isErr). Functional composition methods (map, andThen, orElse, etc.) to avoid deep if nesting for success/failure checks. Modern TS practices (strict types, ESM/CJS exports). We were evolving an internal version that started looking like Result anyway, so we decided to build a clean, open-source implementation based on the Rust API. While there are other libraries (some older, some part of larger FP ecosystems like fp-ts/effect-ts), our goal was a minimal, easy-to-adopt implementation of just the Result pattern itself. It doesn't magically replicate Rust's ? operator or compiler guarantees, and you still need try-catch at boundaries with exception-throwing code, but we've found it helpful for adding clarity and type-safety to our core logic where specific failure states are expected domain outcomes. Links: GitHub (Source/Docs): https://github.com/TrylonAI/ts-result npm (@trylonai/ts-result): https://www.npmjs.com/package/@trylonai/ts-result We wrote a blog post detailing the motivation, our journey from internal tools, design choices, and how it compares to exceptions or larger FP libraries: https://trylonai.github.io/ts-result/ts-result-blog-post.htm... Would love to hear your thoughts and feedback
Share cardActual performance
Launch Intel predictions
Analyze your own launch →Correct prediction on native model
Similar products
Impls – Determine if a Rust type implements a logical trait expression
Stack Error – Simple and informative errors for Rust
Rust-like error handling in Python thanks to PEP 622
Ordered Error Diffusion Dithering
Zig Without Unused Variable Error
ts-error-tuple – Concise and type-safe error handling for TypeScript
Rust trait with lifetime, type, const and associated type arguments
Result monad for Elixir inspired by Rust Result type
Screencast: An Introduction to Rust
Oxischeme – A Scheme implementation in Rust