Ts

Ts-result – Rust's Result<T, E> type for explicit error handling in TS

Hacker News

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 card

Actual performance

2points
1comments
Did not reach leaderboard

Launch Intel predictions

Analyze your own launch →
Indie HackersFits the IH revenue-focused audience · Strong signals: started · Missing: supports, reddit linkedin, podcasting
72%72% predicted probability of success on Indie Hackers, based on ML models trained on real launch data.
best fitHighest predicted score across all platforms for this description.
Product HuntOn track for Day 1 leaderboard · Strong signals: code, open · Missing: mac, agents, macos
70%70% predicted probability of success on Product Hunt, based on ML models trained on real launch data.
Hacker NewsMay not resonate with HN audience · Strong signals: ide, io · Missing: https docs, excited, just released
44%44% predicted probability of success on Hacker News, based on ML models trained on real launch data.
nativeThis product was originally launched on this platform.
TrustMRRLess likely to generate early MRR · Strong signals: way · Missing: mobile apps, ios, personal
40%40% predicted probability of success on TrustMRR, based on ML models trained on real launch data.
AppSumoMay struggle as an AppSumo deal · Missing: plus, platform, intuitive
34%34% predicted probability of success on AppSumo, based on ML models trained on real launch data.
Acquire.comPre-revenue stage for this audience · Missing: arr, mrr, revenue
15%15% predicted probability of success on Acquire.com, based on ML models trained on real launch data.
BetaListMay not resonate with beta-testers · Missing: web3, chat, crypto
0%0% predicted probability of success on BetaList, based on ML models trained on real launch data.

Correct prediction on native model

Similar products

Im
Impls – Determine if a Rust type implements a logical trait expression53%Launch Intel prediction score: how likely this product is to succeed on its source platform, based on its name, tagline, and description.

Impls – Determine if a Rust type implements a logical trait expression

Hacker News1
St
Stack Error – Simple and informative errors for Rust35%Launch Intel prediction score: how likely this product is to succeed on its source platform, based on its name, tagline, and description.

Stack Error – Simple and informative errors for Rust

Hacker News2
Ru
Rust-like error handling in Python thanks to PEP 62236%Launch Intel prediction score: how likely this product is to succeed on its source platform, based on its name, tagline, and description.

Rust-like error handling in Python thanks to PEP 622

Hacker News6
Or
Ordered Error Diffusion Dithering66%Launch Intel prediction score: how likely this product is to succeed on its source platform, based on its name, tagline, and description.

Ordered Error Diffusion Dithering

Hacker News37
Zi
Zig Without Unused Variable Error60%Launch Intel prediction score: how likely this product is to succeed on its source platform, based on its name, tagline, and description.

Zig Without Unused Variable Error

Hacker News1
ts
ts-error-tuple – Concise and type-safe error handling for TypeScript28%Launch Intel prediction score: how likely this product is to succeed on its source platform, based on its name, tagline, and description.

ts-error-tuple – Concise and type-safe error handling for TypeScript

Hacker News1
Ru
Rust trait with lifetime, type, const and associated type arguments43%Launch Intel prediction score: how likely this product is to succeed on its source platform, based on its name, tagline, and description.

Rust trait with lifetime, type, const and associated type arguments

Hacker News2
Re
Result monad for Elixir inspired by Rust Result type60%Launch Intel prediction score: how likely this product is to succeed on its source platform, based on its name, tagline, and description.

Result monad for Elixir inspired by Rust Result type

Hacker News39
Sc
Screencast: An Introduction to Rust57%Launch Intel prediction score: how likely this product is to succeed on its source platform, based on its name, tagline, and description.

Screencast: An Introduction to Rust

Hacker News3
Ox
Oxischeme – A Scheme implementation in Rust56%Launch Intel prediction score: how likely this product is to succeed on its source platform, based on its name, tagline, and description.

Oxischeme – A Scheme implementation in Rust

Hacker News18