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
- Composable —
map,flatMap, andfilterchain without nested conditionals - Foundation for
@ekz— used by@ekz/async-data,@ekz/formixpeer deps, and app code
An Option<A> is either:
Some(value)— a present value (includingnullasOption<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
- Getting started — create options and read values safely
- Constructors —
Some,None,Option.of - Transformations —
map,flatMap,filter - Unwrapping —
getOrElse,getOrUndefined, and when not to callget()