Package Exports
- might-fail
- might-fail/dist/index.js
This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (might-fail) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.
Readme
Might Fail
A TypeScript library for handling async errors without try and catch blocks. Inspired by other languages that utilize Result or Either types for safer error handling.
Quick Start
Install
npm install might-failWrap Promise in mightFail
const {error, result: posts} = await mightFail(fetch("/posts"))
if (error) {
// handle error
return
}
posts!.map(post => console.log(post.title))Or Wrap Async Function in makeMightFail
const mfFetch = makeMightFail(fetch)
const {error, result: posts} = await mfFetch("/posts")
if (error) {
// handle error
return
}
posts!.map(post => console.log(post.title))Either Type
awaiting the mightFail functions will return an Either type with either an error or a result.
erroralways has the typeError | undefined.resultalways has the typeT | undefinedwhereTis the type of the result of the promise passed tomightFail.
This means that the you never lose the type information of the result of the promise passed to mightFail.