Converts a nullable value to an Optional.
Optional
This is the primary way to lift nullable values (null or undefined) into the Optional type system. The function treats both null and undefined as empty values, converting them to None.
null
undefined
None
The type of the nullable value.
The nullable value to convert.
Some<NonNullable<T>> if the value is not null or undefined, otherwise None.
Some<NonNullable<T>>
const present = Optional.fromNullable('hello');const absent = Optional.fromNullable<string | null>(null);assert.deepStrictEqual(present, Optional.some('hello'));assert.deepStrictEqual(absent, Optional.none); Copy
const present = Optional.fromNullable('hello');const absent = Optional.fromNullable<string | null>(null);assert.deepStrictEqual(present, Optional.some('hello'));assert.deepStrictEqual(absent, Optional.none);
Converts a nullable value to an
Optional.This is the primary way to lift nullable values (null or undefined) into the Optional type system. The function treats both
nullandundefinedas empty values, converting them toNone.