isOption
@ts-rust/std / Option / isOption
Function: isOption()
function isOption(x): x is Option<unknown>;
Defined in: packages/std/src/option/option.ts:175
Checks if a value is an Option, narrowing its type to Option<unknown>
.
This type guard verifies whether the input conforms to the Optional interface, indicating it is either a Some or None.
Parameters
Parameter | Type | Description |
---|---|---|
|
| The value to check. |
Returns
x is Option<unknown>
true
if the value is an Option, narrowing to Option<unknown>
.
Example
const x: unknown = some(42);
const y: unknown = none<number>();
const z: unknown = "not an option";
expect(isOption(x)).toBe(true);
expect(isOption(y)).toBe(true);
expect(isOption(z)).toBe(false);
if (isOption(x)) {
expect(x.isSome()).toBe(true); // Type narrowed to Option<unknown>
}