yarut
v1.3.5
Published
A result/option utility for typescript.
Downloads
17
Readme
yarut - Yet Another Result Utility for Typescript
A result/option utility for typescript.
import { Result, Ok, Err } from "yarut";
const apiCall = (): Result<string, Error> => {
return ResultUtil.Ok("All good!");
}
const result = apiCall();
// With help of these type guards, either `value` or `error` is available
if (result.isOk()) {
console.log("It works!", result.value);
} else {
console.log("Oh no :(", result.error);
}
Features
Result
- Encode errors as type information and explicitly handle themOption
- Don't use null/undefined to express values that doesn't exist. UseNone
andSome
to indicate it.
Superjson support
import {optionSuperRegisterRecipe, resultSuperRegisterRecipe } from "yarut";
import superjson from "superjson";
superjson.registerCustom(resultSuperRegisterRecipe(superjson), "yarut/Result");
superjson.registerCustom(optionSuperRegisterRecipe(superjson), "yarut/Option");
Acknowledgements
Inspired by the work of @swan-io/boxed