ts-chas is a functional programming and utility library for TypeScript. It gives you a tightly integrated set of tools for writing code that is explicit about errors, safe at runtime, and easy to reason about without requiring a complete architectural overhaul of your project.
Why ts-chas?
TypeScript gives you compile-time safety, but several common patterns still leave you exposed at runtime:try/catchmakes errors untyped (unknown) and control flow implicitnullandundefinedchecks are easy to forget and don’t compose- Raw Promises have no built-in retry, timeout, or cancellation
- Runtime validation is often bolted on separately from the rest of your types
ts-chas addresses all of these with a single cohesive library.
The modules
Result
Replace
try/catch with Result<T, E> (error types live in the function signature, not in your head).Guard
Chainable runtime validators that are also TypeScript type predicates. Use them inline or as schemas.
Task
Lazy async pipelines with retries, timeouts, circuit breakers, and caching built in.
Tagged Errors
Discriminated error unions that let you match errors exhaustively, just like you match on data.
Option
Model optional values explicitly.
Option<T> shares the entire Result API.Pipe & Flow
Compose small, focused functions into readable pipelines with full type inference.
How the modules fit together
What makests-chas different from a collection of unrelated utilities is that all modules are designed to interoperate:
- A
Guardcan produce aResultdirectly via.parse() - An
Optioncan be converted to aTaskviaTask.fromOption() - A
Resultcan be converted to anOptionvia.toOption() Taskalways resolves to aResultAsyncTagged Errorswork with.catchTag()onResult,ResultAsync, andTask
Ready to start?
Installation
Install ts-chas and set up your imports.
Quick Start
A practical walkthrough with copy-paste examples.