A zero dependencies library for bringing Rust's Option<T>
and Result<T, E>
to TypeScript.
npm install @kherge/result
import { Option, Result, err, none, ok, some } from '@kherge/result';
// Using Option<T>.
let option: Option<string>;
option = some('My string.');
console.log(option.unwrap()); // My string.
option = none();
console.log(option.unwrap()); // throws error
// Using Result<T, E>.
let result: Result<string, number>;
result = ok('My string.');
console.log(result.unwrap()); // My string.
result = err(123);
console.log(result.unwrap()); // throws error
Please see the GitHub Pages site for documentation.
Created using TSDX.
Development can be started after installing the development dependencies.
npm install
npm run build
Builds to the dist/
folder.
npm run build:docs
Builds the documentation to the docs/
folder.
npm test
You can also run
npm run test:watch
to use interactive watch mode.
Generated using TypeDoc