fromNullable
@ts-rust/std / Option / fromNullable
Function: fromNullable()
function fromNullable<T>(value): Option<NonNullable<T>>;
Defined in: packages/std/src/option/option.ts:89
Creates an Option from a value that may be null or undefined.
Returns Some if the value is present, or None if it is
null or undefined.
Type Parameters
| Type Parameter | Description |
|---|---|
| The type of the input value. |
Parameters
| Parameter | Type | Description |
|---|---|---|
|
| A value that may be |
Returns
Option<NonNullable<T>>
Some with the non-nullable value, or None.
Example
const x = fromNullable(42);
const y = fromNullable<number | null>(null);
const z = fromNullable<string | undefined>(undefined);
expect(x).toStrictEqual(some(42));
expect(y.isNone()).toBe(true);
expect(z.isNone()).toBe(true);