Wraps a function to return a Result instead of throwing errors.
The function type.
The type of the error.
The function to wrap.
Optional
Options for error handling.
A function that returns a Result.
const safeParse = fromThrowable(JSON.parse);const [error, data] = safeParse('{"foo": "bar"}');if (error) { console.error(error.message);} else { console.log(data);} Copy
const safeParse = fromThrowable(JSON.parse);const [error, data] = safeParse('{"foo": "bar"}');if (error) { console.error(error.message);} else { console.log(data);}
Wraps a function to return a Result instead of throwing errors.