A Result
type for typescript
A Result
type is a type holding a returned value or an error code. They provide
an elegant way of handling errors, without resorting to exception handling.
Read more on wikipedia
Typescript does not have a native Result
type
npm i @ixl/result
import { Result, Ok, Err } from '@ixl/result';
function mayFail(a: string): Result<number, string> {
if (a == 'fail') {
return new Err('something went wrong');
}
return new Ok(123);
}
For more examples, see the documentation
Generated using TypeDoc