Skip to main content

ts-rust

Rust-inspired utilities for TypeScript

npm install @ts-rust/std
Documentation

Safe and Explicit

Option and Result types ensure you handle optional values and errors explicitly — no more Cannot read property of undefined.

Async Built-in

PendingOption and PendingResult bring the same safety to async workflows. Chain .map, .andThen, and .unwrapOr across promises without unhandled rejections.

Rust-Inspired API

Familiar methods like unwrap, expect, map, and match — modeled after Rust's standard library, adapted for TypeScript.

Quick Example

import { some, none, ok, err } from "@ts-rust/std";

// Option: handle missing values explicitly
function findUser(id: number) {
return id === 1 ? some("Alice") : none();
}

findUser(1).unwrapOr("Guest"); // "Alice"
findUser(2).unwrapOr("Guest"); // "Guest"

// Result: handle errors as values
function divide(a: number, b: number) {
return b !== 0 ? ok(a / b) : err("Division by zero");
}

divide(10, 2).unwrapOr(0); // 5
divide(10, 0).unwrapOr(0); // 0