<L extends SchemaAST.LiteralValue>(literal: L, name?: string): Config<L>Creates a config that only accepts a specific literal value.
When to use
Use to restrict a config to a single, specific literal value.
Details
Shortcut for Config.schema(Schema.Literal(literal), name).
Example (Restricting to a literal)
import { Config } from "effect"
const env = Config.literal("production", "ENV")export function function literal<
L extends SchemaAST.LiteralValue
>(literal: L, name?: string): Config<L>
Creates a config that only accepts a specific literal value.
When to use
Use to restrict a config to a single, specific literal value.
Details
Shortcut for Config.schema(Schema.Literal(literal), name).
Example (Restricting to a literal)
import { Config } from "effect"
const env = Config.literal("production", "ENV")
literal<function (type parameter) L in literal<L extends SchemaAST.LiteralValue>(literal: L, name?: string): Config<L>L extends import SchemaASTSchemaAST.type LiteralValue =
| string
| number
| bigint
| boolean
The set of primitive types that can appear as a
Literal
value.
LiteralValue>(literal: L extends SchemaAST.LiteralValueliteral: function (type parameter) L in literal<L extends SchemaAST.LiteralValue>(literal: L, name?: string): Config<L>L, 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(import SchemaSchema.function Literal<
L extends SchemaAST.LiteralValue
>(literal: L): Literal<L>
Creates a schema for a single literal value (string, number, bigint, boolean, or null).
Example (Defining a string literal)
import { Schema } from "effect"
const schema = Schema.Literal("hello")
// Type: Schema.Literal<"hello">
Literal(literal: L extends SchemaAST.LiteralValueliteral), name: string | undefinedname)
}