Hi there! Are you looking for the official Deno documentation? Try docs.deno.com for all your Deno learning needs.

Option

deprecated

Consider to use Nullable<T>, Undefinable<T>, or Maybe<T> to express an absence of a value. In JavaScript, they satisfy almost use cases. Probably, you might not have to use this type.


This is option type.

CAUTION:

Be careful to use === or Object.is() to compare the equality of this type

You should use equal operator to check the equality for two objects of this type instead of === or Object.is(). Operators for this type sometimes return the inputted object directly to avoid an unnecessary objecti allocation.

We use this design by the assumption that we would not compare a and b usually in the following case. It usually suggest some design problems if you would like to compare these a and b.

const a = createSome(val);
const b = andThen(a, someOperation);

Remarks

In almost of cases of JavaScript, it's more ergonomic to use Nullable<T>, Undefinable<T>, or Maybe<T> to represent that either there is some value or not. We also recommend to use them instead of this type generally.

However, this type is usefil in following case:

 1. Migration solution from `PlainResult<T, void>` to `Nullable<T>`, `Undefinable<T>`, or `Maybe<T>`.
 2. You need to treat `null` or `undefined` as some value rather than absence of value.

Then this tagged type helps you powerfully.

@deprecated

37.1.0

type Option<T> = Some<T> | None;

§Type Parameters

§Type