UNPKG

@piyawasin/attempt

Version:

A minimal, type-safe utility for defensive error handling in JS/TS. Inspired by Go, it uses tuple-based returns to eliminate try-catch nesting and handle synchronous/asynchronous errors predictably.

8 lines (7 loc) 331 B
/** * Executes a function and returns a tuple [result, error]. * @param func Function to execute * @param args Arguments to pass to the function */ import type { AttemptResult } from "./types"; export declare function attempt<T, Args extends any[], E = unknown>(func: (...args: Args) => T, ...args: Args): AttemptResult<T, E>;