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