(input: unknown): input is Option<unknown>Determines whether the given value is an Option.
When to use
Use to validate unknown values at runtime boundaries, such as type-narrowing in union types.
Details
- Returns
truefor bothSomeandNoneinstances - Acts as a type guard, narrowing the input to
Option<unknown>
Example (Checking if a value is an Option)
import { Option } from "effect"
console.log(Option.isOption(Option.some(1)))
// Output: true
console.log(Option.isOption(Option.none()))
// Output: true
console.log(Option.isOption({}))
// Output: falseSource effect/Option.ts:3281 lines
export const const isOption: (
input: unknown
) => input is Option<unknown>
Determines whether the given value is an Option.
When to use
Use to validate unknown values at runtime boundaries, such as type-narrowing
in union types.
Details
- Returns
true for both Some and None instances
- Acts as a type guard, narrowing the input to
Option<unknown>
Example (Checking if a value is an Option)
import { Option } from "effect"
console.log(Option.isOption(Option.some(1)))
// Output: true
console.log(Option.isOption(Option.none()))
// Output: true
console.log(Option.isOption({}))
// Output: false
isOption: (input: unknowninput: unknown) => input: unknowninput is type Option<A> = None<A> | Some<A>The Option data type represents optional values. An Option<A> is either
Some<A>, containing a value of type A, or None, representing absence.
When to use
Use to represent initial values that may not yet exist
- Returning from partial functions (not defined for all inputs)
- Managing optional fields in data structures
Namespace containing utility types for Option.
When to use
Use to access type-level helpers associated with Option.
Option<unknown> = import optionoption.const isOption: (
input: unknown
) => input is Option.Option<unknown>
isOptionReferenced by 2 symbols