Skip to content

Repository files navigation

Resultar Workspace

Resultar makes expected failures visible in TypeScript signatures and keeps them composable through sync, async, retry, timeout, concurrency, cleanup, and exhaustive boundary workflows. The workspace contains the core library, HTTP request adapters, compiler-backed diagnostics, and runnable examples.

If you are evaluating or using the main library, start with:

Packages

Package Purpose Documentation
resultar Core Result<T, E>, lazy ResultTask<T, E, R>, and ResultAsync<T, E> library with tagged errors, typed services, async policies, redaction, and strict aliases. package README, full guide
resultar-check Native TypeScript 7 compiler checks plus type-aware Resultar diagnostics. check README
resultar-request Fetch-first JSON request helper with Resultar errors, validation, retry, and error mapping. request README
resultar-di Typed dependency composition, scoped resources, and overrides for ResultTask applications. DI README
resultar-request-typebox TypeBox adapter for resultar-request. TypeBox adapter README
resultar-request-zod Zod adapter for resultar-request. Zod adapter README
resultar-hono Typed Hono bindings with one DI scope per response and explicit shutdown. Hono README
resultar-fastify Native Fastify application/request services, cancellation and resource scopes. Fastify README

Main Library

Install the core package when you want expected failures in function signatures instead of hidden behind throw, rejected promises, nullable returns, or ad hoc T | Error unions.

pnpm add resultar
npm install resultar

The npm package README is packages/resultar/README.md. It covers the selling points and quick-start examples for:

  • Result<T, E>, lazy ResultTask<T, E, R>, and ResultAsync<T, E>
  • explicit ResultTask execution with typed services, generator composition, defects, and cleanup
  • StrictResult<T, E extends Error> and StrictResultAsync<T, E extends Error>
  • createTaggedError, taggedEnum, and redacted error props
  • reusable pipe combinators for Result and ResultAsync
  • ResultAsync.timeout, retry, retryOrElse, race, raceAll, and withResource
  • Result.gen/safeTry, matchTags, local recovery, and boundary response mapping

Documentation Map

Use the full guide when you need a specific recipe:

Topic Link
Core model The Model
Tagged errors Tagged Errors
Redacted error props Redacted Error Props
Catching and recovering errors Catching And Recovering Errors
Async wrapping Wrapping Throwing Or Rejecting Code
Lazy workflows Lazy tasks and requirements
Local recovery Recovering Tagged Errors Locally
Async racing and timeouts Concurrent Racing And Timeouts
Async retry policies Retrying Async Work
Bounded async mapping Async Concurrency Mapping
Resource cleanup Resourceful Async Iterables
Safe linear result code Safe Try
Validation error recipes Validation Error Recipes
No-discard diagnostics No-Discard Validation
Public exports Public Entry Point

Resultar Check

Use resultar-check as the canonical Resultar diagnostics command. Its native TypeScript-Go backend runs the compiler first, then runs every enabled Resultar diagnostic over the same tsconfig.json.

pnpm add -D resultar-check
{ "scripts": { "check": "resultar-check" } }

resultar-check defaults to tsconfig.json and runs TypeScript with no emit.

Version 3 is native-only: a small Node launcher selects a platform package, then the TypeScript-Go binary performs compiler diagnostics and all Resultar rules in one project pass. It also exposes:

  • human, JSON Lines, SARIF 2.1.0, and JUnit output;
  • configurable severities, file overrides, suppressions, and CI failOn policy;
  • a stdio LSP server with diagnostics and safe composition quick fixes;
  • init and doctor commands for a portable Zed setup;
  • macOS, Linux, and Windows binaries for ARM64 and x64.

See packages/check/README.md for the recommended noDiscard, noThrow, and noTryCatch configuration, every diagnostic, output formats, editor setup, and the v3 migration guide.

Examples

Example Surface What it validates
examples/resultar Core Resultar cookbook Sync validation, safeTry, tagged errors, async resilience, and resource cleanup
examples/check Native diagnostics Exact findings for all supported rules plus a zero-diagnostic clean project
examples/request Request helpers Fetch-style JSON calls with TypeBox and Zod adapters
examples/hono Hono + DI application Class services, inferred AppHono bindings, overrides and response scopes (Node)
examples/fastify Native Fastify + DI Class services, TypeBox routes, inferred request services and explicit HTTP mapping

Both HTTP examples use three files: services.ts defines and registers services, routes.ts maps results to native HTTP responses, and main.ts creates and starts the app. They import DI helpers from their framework adapter and omit bindings to expose all registered services. Pass bindings: ["health", "users"] to restrict the view, or bindings: [] to select none. Fastify declares request.services in main.ts; Hono exports AppHono there for route files. Both derive service types with InferRequestServices<typeof createApplication>.

To start an example, enter examples/fastify or examples/hono and run pnpm dev. Both default to port 3000; use different PORT values if running them together.

Run all example smokes with:

pnpm test:examples
pnpm test:agents

Development

Common workspace checks:

pnpm check:full
pnpm build
pnpm smoke:package
pnpm test:examples

Release metadata is managed with Changesets. Add a changeset with the feature or fix:

pnpm changeset

After the change merges to main, the Release workflow opens or updates a Version packages PR. When that PR is merged, CI publishes npm and JSR from the versioned package metadata.

Dry-run publish checks:

pnpm run release:npm -- --dry-run
pnpm run release:jsr -- --dry-run

Requirements

  • Node.js 24+
  • ESM-only core package

The root package is private. Published package metadata and README content live in each package directory.

Hono integration

resultar-hono connects typed DI services to ordinary Hono handlers, with one scope per response and explicit application shutdown. See the runnable example; port and runtime configuration stay in the bootstrap.

For an existing Hono router, use createHonoServices(module).middleware(keys) to infer c.var.services per route while preserving runtime bindings and RPC types.

Fastify integration

resultar-fastify registers native application and request services over the same DI scopes. Keep ordinary async handlers and explicit reply.code().send() mappings; the plugin manages resource ownership through streamed replies and shutdown. The Fastify example includes UsersRepository and Users classes with requires, function-based Health, and TypeBox routes.

Coding-agent validation

Run pnpm test:agents to verify executable coding contracts and their deliberately broken variants without model calls. See the evaluation guide to grade generated submissions or compare model runs with and without the bundled skill.

About

Resultar is a TypeScript library for robust, type-safe error handling without throwing exceptions. It's a fork of the neverthrow library, adding features for more flexibility in error handling

Resources

Stars

5 stars

Watchers

2 watching

Forks

Releases

Packages

Used by

Contributors

Languages