Skip to main content

Option - API

Option represents an optional value: it is either some and contains a value, or none, and does not.

In contrast with the full-fledged Option<T> from fp-tp, this module provides just the bare minimum. If you require more features, consider using fp-tp.

Installation

npm is the default package manager for Node.js, and to where tscommon is published.
Your project is using npm if it has a package-lock.json file in its root folder.

Run the following command in your terminal:

terminal
npm install @tscommon/option

Usage

main.ts
import { None, Option, Some } from '@tscommon/option';

let data: Option<number> = Option.some(42);

if (Option.is(data, Some)) {
// Data is present
}

data = Option.none;

if (Option.is(data, None)) {
// Data is absent
}