<A>(self: Config<A>): Config<Option.Option<A>>Makes a config optional: returns Some(value) on success and None when
data is missing.
When to use
Use when you need to handle a config key that may or may not be present.
Gotchas
Like withDefault, only missing-data errors produce None.
Validation errors still propagate.
Example (Reading optional config)
import { Config, ConfigProvider, Effect } from "effect"
const maybePort = Config.option(Config.number("port"))
const provider = ConfigProvider.fromUnknown({})
// Effect.runSync(maybePort.parse(provider)) // { _tag: "None" }export const const option: <A>(
self: Config<A>
) => Config<Option.Option<A>>
Makes a config optional: returns Some(value) on success and None when
data is missing.
When to use
Use when you need to handle a config key that may or may not be present.
Gotchas
Like
withDefault
, only missing-data errors produce None.
Validation errors still propagate.
Example (Reading optional config)
import { Config, ConfigProvider, Effect } from "effect"
const maybePort = Config.option(Config.number("port"))
const provider = ConfigProvider.fromUnknown({})
// Effect.runSync(maybePort.parse(provider)) // { _tag: "None" }
option = <function (type parameter) A in <A>(self: Config<A>): Config<Option.Option<A>>A>(self: Config<A>(parameter) self: {
parse: (provider: ConfigProvider.ConfigProvider, pathPrefix?: Path) => Effect.Effect<T, ConfigError>;
pipe: { <A>(this: A): A; <A, B = never>(this: A, ab: (_: A) => B): B; <A, B = never, C = never>(this: A, ab: (_: A) => B, bc: (_: B) => C): C; <A, B = never, C = never, D = never>(this: A, ab: (_: A) => B, bc: (_: B) => C, cd: (_: C) => D): D; <…;
toString: () => string;
toJSON: () => unknown;
}
self: interface Config<out T>A recipe for extracting a typed value T from a ConfigProvider.
When to use
Use to describe typed configuration that can be parsed from a provider or
yielded inside Effect.gen.
Details
Key members:
parse(provider, pathPrefix?) – runs the config against a specific provider.
The optional path prefix is the logical scope accumulated from outer
Config.nested calls.
- Yieldable – can be yielded inside
Effect.gen, which automatically
resolves the current ConfigProvider from the context.
- Pipeable – supports
.pipe(Config.map(...)) etc.
Config<function (type parameter) A in <A>(self: Config<A>): Config<Option.Option<A>>A>): interface Config<out T>A recipe for extracting a typed value T from a ConfigProvider.
When to use
Use to describe typed configuration that can be parsed from a provider or
yielded inside Effect.gen.
Details
Key members:
parse(provider, pathPrefix?) – runs the config against a specific provider.
The optional path prefix is the logical scope accumulated from outer
Config.nested calls.
- Yieldable – can be yielded inside
Effect.gen, which automatically
resolves the current ConfigProvider from the context.
- Pipeable – supports
.pipe(Config.map(...)) etc.
Config<import OptionOption.type Option<A> = Option.None<A> | Option.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<function (type parameter) A in <A>(self: Config<A>): Config<Option.Option<A>>A>> =>
self: Config<A>(parameter) self: {
parse: (provider: ConfigProvider.ConfigProvider, pathPrefix?: Path) => Effect.Effect<T, ConfigError>;
pipe: { <A>(this: A): A; <A, B = never>(this: A, ab: (_: A) => B): B; <A, B = never, C = never>(this: A, ab: (_: A) => B, bc: (_: B) => C): C; <A, B = never, C = never, D = never>(this: A, ab: (_: A) => B, bc: (_: B) => C, cd: (_: C) => D): D; <…;
toString: () => string;
toJSON: () => unknown;
}
self.Pipeable.pipe<Config<A>, Config<Option.Option<A>>, Config<Option.Option<never> | Option.Option<A>>>(this: Config<A>, ab: (_: Config<A>) => Config<Option.Option<A>>, bc: (_: Config<Option.Option<A>>) => Config<Option.Option<never> | Option.Option<A>>): Config<Option.Option<never> | Option.Option<A>> (+21 overloads)pipe(const map: {
<A, B>(f: (a: A) => B): (
self: Config<A>
) => Config<B>
<A, B>(
self: Config<A>,
f: (a: A) => B
): Config<B>
}
map(import OptionOption.const some: <A>(value: A) => Option<A>Wraps the given value into an Option to represent its presence.
When to use
Use to wrap a known present value as Option
- Returning a successful result from a partial function
Details
- Always returns
Some<A>
- Does not filter
null or undefined; use
fromNullishOr
for that
Example (Wrapping a value)
import { Option } from "effect"
// ┌─── Option<number>
// ▼
const value = Option.some(1)
console.log(value)
// Output: { _id: 'Option', _tag: 'Some', value: 1 }
some), const withDefault: {
<A2>(defaultValue: A2): <A>(
self: Config<A>
) => Config<A2 | A>
<A, A2>(
self: Config<A>,
defaultValue: A2
): Config<A | A2>
}
withDefault(import OptionOption.const none: <A = never>() => Option<A>Creates an Option representing the absence of a value.
When to use
Use to represent a missing or uninitialized value, such as returning "no
result" from a function.
Details
- Returns
Option<never>, which is a subtype of Option<A> for any A
- Always returns the same singleton instance
Example (Creating an empty Option)
import { Option } from "effect"
// ┌─── Option<never>
// ▼
const noValue = Option.none()
console.log(noValue)
// Output: { _id: 'Option', _tag: 'None' }
none()))