rusty-result-ts
TypeScript icon, indicating that this package has built-in type declarations

0.1.1 • Public • Published

rusty-result-ts

A very simple recreation of Rust's Return type for TypeScript.

Usage example

function ValidateNumber(value: number): Result<number, string> {
    if (value > 0) {
        return ok(value);
    } else {
        return err('value must be greater than 0');
    }
};

const result = ValidateNumber(10);
if (result.isOk()) {
    console.log(result.value);
} else {
    console.log(`Encountered error: ${result.error}`);
}

Development

  • This project is using pnpm as a package manager.
  • Run pnpm install to install dependencies.
  • Run pnpm test to run tests once.
  • Run pnpm test:watch to run tests in watch mode.
  • Run pnpm build to build the project - this will also run the linter (EsLint).

Package Sidebar

Install

npm i rusty-result-ts

Weekly Downloads

15

Version

0.1.1

License

ISC

Unpacked Size

5.36 kB

Total Files

11

Last publish

Collaborators

  • xkonti