Options
All
  • Public
  • Public/Protected
  • All
Menu

@ixl/result

Result

A Result type for typescript

What?

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

Why?

Typescript does not have a native Result type

Features:

Install and Use

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