never-catch
v1.1.0
Published
A design pattern to implement result in functions.
Downloads
44
Maintainers
Readme
never-catch
- No boilerplate
- Type support
- Auto type infer
const divideTenBy = (a: number) => {
if (a === 0) {
return err('divide by zero');
} else {
return ok(10 / a);
}
};
const result = divideTenBy(5);
if (result.ok) {
console.log(result.value);// OK
} else {
console.log(result.error);// Ok
console.log(result.value);// TS2339: Property 'value' does not exist on type 'Err '.
}
Email: [email protected]