fn
tryIt
v0.0.3testedWraps promise-based code in a try/catch block without forking the control flow
Examples
ts
const wrappedFetch = tryIt(fetch);
const { error, data } = await wrappedFetch('https://jsonplaceholder.typicode.com/todos/1');ts
const { error, data } = await tryIt(fetch)('https://jsonplaceholder.typicode.com/todos/1');Signature
ts
export function tryIt<Args extends any[], Return>(
fn: (...args: Args) => Return,
){ ... }Type Parameters
Argsextends any[]ReturnParameters
| Parameter | Type | Description |
|---|---|---|
fn | (...args: Args) => Return | The function to try |
Returns
(...args: Args) => TryItReturn<Return>- The function that will return a tuple with the error and the result