Skip to main content

Option

Option (@ekz/option) is a TypeScript port of Scala's Option / Maybe type. It replaces null and undefined in domain logic with an explicit Some or None.

Why use Option?

  • No surprise nulls — absence is part of the type
  • Composablemap, flatMap, and filter chain without nested conditionals
  • Foundation for @ekz — used by @ekz/async-data, @ekz/formix peer deps, and app code

An Option<A> is either:

  • Some(value) — a present value (including null as Option<null> if you construct it explicitly)
  • None — no value

Install

npm install @ekz/option
# or
yarn add @ekz/option

Zero runtime dependencies.

Quick taste

import { Option, Some, None } from '@ekz/option';

const doubled = Option.of(maybeNumber).map((n) => n * 2).getOrElse(() => 0);

Some('hello')
.flatMap((s) => Some(`${s}!`))
.getOrUndefined(); // 'hello!'

Next steps