Skip to main content
Module

x/optionals/mod.ts>Ok

Rust-like error handling and options for TypeScript and Deno!
Latest
function Ok
Re-export
import { Ok } from "https://deno.land/x/optionals@v3.0.0/mod.ts";

Return a non-error value result.

Examples

Example 1

function divide(left: number, right: number): Result<number, Error> {
  if (right === 0) return Err("Divided by zero");

  return Ok(left / right);
}

Example 2

const foo = Ok("Foo!");

if (foo instanceof Ok) {
 // Do something
}

Type Parameters

T
E extends Error

Parameters

optional
input: T

a value that does not extend the Error type.