Skip to content

Instantly share code, notes, and snippets.

@mohilcode
mohilcode / result.ts
Last active April 24, 2025 08:45
typescript implementation of the result pattern for functional error handling. provides type-safe alternatives to try/catch with monadic operations for composition. use this to make error handling explicit in your function signatures and avoid throwing exceptions
import { inspect } from 'util'
export type Success<T> = {
readonly type: 'success'
readonly data: T
readonly error?: never
}
export type Failure<E> = {
readonly type: 'failure'