(name?: string): Config<boolean>Creates a config for a boolean value parsed from common string representations.
When to use
Use to read boolean flags from string-like config sources.
Details
Shortcut for Config.schema(Config.Boolean, name).
Accepted values: true, false, yes, no, on, off, 1, 0,
y, n.
Example (Reading a boolean flag)
import { Config, ConfigProvider, Effect } from "effect"
const program = Effect.gen(function*() {
const flag = yield* Config.boolean("FEATURE_FLAG")
console.log(flag)
})
const provider = ConfigProvider.fromEnv({
env: {
FEATURE_FLAG: "yes"
}
})
Effect.runSync(
program.pipe(Effect.provideService(ConfigProvider.ConfigProvider, provider))
)
// Output: trueexport function function boolean(
name?: string
): Config<boolean>
Creates a config for a boolean value parsed from common string
representations.
When to use
Use to read boolean flags from string-like config sources.
Details
Shortcut for Config.schema(Config.Boolean, name).
Accepted values: true, false, yes, no, on, off, 1, 0,
y, n.
Example (Reading a boolean flag)
import { Config, ConfigProvider, Effect } from "effect"
const program = Effect.gen(function*() {
const flag = yield* Config.boolean("FEATURE_FLAG")
console.log(flag)
})
const provider = ConfigProvider.fromEnv({
env: {
FEATURE_FLAG: "yes"
}
})
Effect.runSync(
program.pipe(Effect.provideService(ConfigProvider.ConfigProvider, provider))
)
// Output: true
boolean(name: string | undefinedname?: string) {
return function schema<T>(
codec: Schema.ConstraintCodec<T, unknown>,
path?: string | ConfigProvider.Path
): Config<T>
Creates a Config<T> from a Schema.Codec.
When to use
Use when you need to read structured or schema-validated configuration.
Details
The optional path sets the local path segment(s) for the config lookup.
It is appended to the logical path prefix accumulated from outer
nested
calls. Pass a single string for a flat key or an array for
nested paths.
Convenience constructors such as string, number, and boolean delegate
to this API.
The codec is used to decode the raw StringTree produced by the provider
into T. Schema validation errors are wrapped in ConfigError.
Example (Reading a structured config)
import { Config, ConfigProvider, Effect, Schema } from "effect"
const DbConfig = Config.schema(
Schema.Struct({
host: Schema.String,
port: Schema.Int
}),
"db"
)
const provider = ConfigProvider.fromUnknown({
db: { host: "localhost", port: 5432 }
})
// Effect.runSync(DbConfig.parse(provider))
// { host: "localhost", port: 5432 }
schema(const Boolean: Schema.decodeTo<
Schema.Boolean,
Schema.Literals<
readonly [
"true",
"yes",
"on",
"1",
"y",
"false",
"no",
"off",
"0",
"n"
]
>,
never,
never
>
const Boolean: {
Type: To["Type"];
Encoded: From["Encoded"];
DecodingServices: To["DecodingServices"] | From["DecodingServices"] | RD;
EncodingServices: To["EncodingServices"] | From["EncodingServices"] | RE;
Iso: To["Iso"];
from: From;
to: To;
Rebuild: Rebuild;
ast: Ast;
annotate: (annotations: Schema.Annotations.Bottom<boolean, readonly []>) => Schema.decodeTo<Schema.Boolean, Schema.Literals<readonly ['true', 'yes', 'on', '1', 'y', 'false', 'no', 'off', '0', 'n']>, never, never>;
annotateKey: (annotations: Schema.Annotations.Key<boolean>) => Schema.decodeTo<Schema.Boolean, Schema.Literals<readonly ['true', 'yes', 'on', '1', 'y', 'false', 'no', 'off', '0', 'n']>, never, never>;
check: (checks_0: SchemaAST.Check<boolean>, ...checks: Array<SchemaAST.Check<boolean>>) => Schema.decodeTo<Schema.Boolean, Schema.Literals<readonly ['true', 'yes', 'on', '1', 'y', 'false', 'no', 'off', '0', 'n']>, never, never>;
rebuild: (ast: SchemaAST.Boolean) => Schema.decodeTo<Schema.Boolean, Schema.Literals<readonly ['true', 'yes', 'on', '1', 'y', 'false', 'no', 'off', '0', 'n']>, never, never>;
make: (input: boolean, options?: MakeOptions) => boolean;
makeOption: (input: boolean, options?: MakeOptions) => Option_.Option<boolean>;
makeEffect: (input: boolean, options?: MakeOptions) => Effect.Effect<boolean, SchemaError, never>;
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; <…;
}
Schema for boolean values encoded as strings.
When to use
Use when you need the reusable boolean schema value for Config.schema with
custom paths.
Details
Accepted string values: true, false, yes, no, on, off, 1,
0, y, n (case-sensitive).
Boolean, name: string | undefinedname)
}