Skip to main content
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/catch makes errors untyped (unknown) and control flow implicit
  • null and undefined checks 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 makes ts-chas different from a collection of unrelated utilities is that all modules are designed to interoperate:
  • A Guard can produce a Result directly via .parse()
  • An Option can be converted to a Task via Task.fromOption()
  • A Result can be converted to an Option via .toOption()
  • Task always resolves to a ResultAsync
  • Tagged Errors work with .catchTag() on Result, ResultAsync, and Task
See Cross-Module Patterns for worked examples.

Ready to start?

Installation

Install ts-chas and set up your imports.

Quick Start

A practical walkthrough with copy-paste examples.