A lightweight optional-value container (similar to Option<T> in functional languages). Avoids returning null / undefined directly from functions that may not produce a value.
Option<T>
null
undefined
const maybeUser: Maybe<User> = findUser(id)if (maybeUser.hasValue()) { const user = maybeUser.instance()} Copy
const maybeUser: Maybe<User> = findUser(id)if (maybeUser.hasValue()) { const user = maybeUser.instance()}
The type of the wrapped value.
Readonly
Returns true if a value is present.
true
Returns the wrapped value, or undefined if absent.
A lightweight optional-value container (similar to
Option<T>in functional languages). Avoids returningnull/undefineddirectly from functions that may not produce a value.Example