@bubblewrap/core
Version:
Core Library to generate, build and sign TWA projects
47 lines (46 loc) • 1.37 kB
TypeScript
/**
* While throwing exceptions show be used to handle truly exception cases, `Result<V, E>` can be
* used to handle cases where failures are expected, therefore not really exceptions.
*
* The outcome can be verified with `Result.isOk()`:
* ```
* const result = someMethod();
* if (result.isOk()) {
* const value = result.unwrap();
* ...
* }
* ```
*/
export declare class Result<V, E extends Error> {
private _result;
private constructor();
/**
* Creates a new `ok` Result, with the outcome `value`.
*/
static ok<V>(value: V): Result<V, any>;
/**
* Creates a new `error` Result, with the outcome `error`.
*/
static error<E extends Error>(error: E): Result<any, E>;
/**
* Returns the value if this result is `ok`. Otherwise, throws `E`.
*/
unwrap(): V;
/**
* If the result is an Error, returns `defaultValue`. Otherwise returns the result value.
*/
unwrapOr(defaultValue: V): V;
/**
* If the result is an Error, returns the `Error` instance without throwing. Otherwise,
* throws an Exception.
*/
unwrapError(): E;
/**
* @returns `true` if the result is `ok`. `false` if it is an `Error`.
*/
isOk(): boolean;
/**
* @returns `true` if the result is an `Error`. `false` if the result is `ok`.
*/
isError(): boolean;
}