Installation
Requirements
- Node.js: 20.0.0+
- TypeScript: 5.0+ (optional, but recommended)
Package Installation
bash
npm install @eriveltondasilva/result.jsbash
bun add @eriveltondasilva/result.jsImport
typescript
import { Result } from '@eriveltondasilva/result.js'typescript
import Result from '@eriveltondasilva/result.js'typescript
import { ok, err } from '@eriveltondasilva/result.js'Named Helpers
ok and err are exported directly as shorthand for Result.ok and Result.err:
typescript
import { ok, err } from '@eriveltondasilva/result.js'
const success = ok(42) // equivalent to Result.ok(42)
const failure = err('oops') // equivalent to Result.err('oops')TypeScript Setup
Result.js is fully typed. No additional configuration needed.
typescript
import { Result, type AsyncResult } from '@eriveltondasilva/result.js'
const result: Result<number, string> = Result.ok(42)
const asyncOp: AsyncResult<User, Error> = Result.fromPromise(() => fetchUser(id))Next Steps
- Quick Start — Learn the basics
- What is Result? — Understand the pattern