Lightweight, enterprise-grade railway-oriented error handling for TypeScript. Minimal syntax, maximum type safety.
pnpm add super-resultimport { from, ok, err } from 'super-result'
// Capture synchronous errors
const res1 = from(() => {
if (Math.random() > 0.5) throw new Error('boom')
return 42
})
// Capture asynchronous errors
const res2 = await from(async () => {
const data = await fetch('...')
return data.json()
})
// Type narrowing
if (res1.ok) {
console.log(res1.value)
} else {
console.error(res1.error.message)
}import { createResult } from 'super-result'
class MyError extends Error {}
const R = createResult(error =>
error instanceof MyError ? error : new MyError(String(error))
)
const res = R.from(() => { throw new Error('raw') })
// res.error is guaranteed to be MyErrorFull API documentation is available in the docs folder.
MIT © simwai