<V extends Schema.Constraint>(
value: V,
options?: { readonly separator?: string | undefined }
): Schema.Union<
readonly [
Schema.compose<
Schema.$Array<V>,
Schema.decodeTo<
Schema.$Array<Schema.String>,
Schema.String,
never,
never
>
>,
Schema.$Array<V>
]
>const const ArrayConfig: <
V extends Schema.Constraint
>(
value: V,
options?: {
readonly separator?: string | undefined
}
) => Schema.Union<
readonly [
Schema.compose<
Schema.$Array<V>,
Schema.decodeTo<
Schema.$Array<Schema.String>,
Schema.String,
never,
never
>
>,
Schema.$Array<V>
]
>
ArrayConfig = <function (type parameter) V in <V extends Schema.Constraint>(value: V, options?: {
readonly separator?: string | undefined;
}): Schema.Union<readonly [Schema.compose<Schema.$Array<V>, Schema.decodeTo<Schema.$Array<Schema.String>, Schema.String, never, never>>, Schema.$Array<...>]>
V extends import SchemaSchema.Constraint>(value: V extends Schema.Constraintvalue: function (type parameter) V in <V extends Schema.Constraint>(value: V, options?: {
readonly separator?: string | undefined;
}): Schema.Union<readonly [Schema.compose<Schema.$Array<V>, Schema.decodeTo<Schema.$Array<Schema.String>, Schema.String, never, never>>, Schema.$Array<...>]>
V, options: | {
readonly separator?: string | undefined
}
| undefined
options?: {
readonly separator?: string | undefinedseparator?: string | undefined
}) => {
const const array: Schema.$Array<V>const array: {
Type: ReadonlyArray<S["Type"]>;
Encoded: ReadonlyArray<S["Encoded"]>;
DecodingServices: S["DecodingServices"];
EncodingServices: S["EncodingServices"];
Iso: ReadonlyArray<S["Iso"]>;
value: S;
Rebuild: Rebuild;
ast: Ast;
annotate: (annotations: Schema.Annotations.Bottom<ReadonlyArray<V['Type']>, readonly []>) => Schema.$Array<V>;
annotateKey: (annotations: Schema.Annotations.Key<ReadonlyArray<V['Type']>>) => Schema.$Array<V>;
check: (checks_0: SchemaAST.Check<ReadonlyArray<V['Type']>>, ...checks: Array<SchemaAST.Check<ReadonlyArray<V['Type']>>>) => Schema.$Array<V>;
rebuild: (ast: SchemaAST.Arrays) => Schema.$Array<V>;
make: (input: ReadonlyArray<V['~type.make']>, options?: MakeOptions) => ReadonlyArray<V['Type']>;
makeOption: (input: ReadonlyArray<V['~type.make']>, options?: MakeOptions) => Option_.Option<ReadonlyArray<V['Type']>>;
makeEffect: (input: ReadonlyArray<V['~type.make']>, options?: MakeOptions) => Effect.Effect<ReadonlyArray<V['Type']>, 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; <…;
}
array = import SchemaSchema.Array<V>(self: V): Schema.$Array<V>
export Array
Defines a ReadonlyArray schema for a given element schema.
Example (Defining an array of strings)
import { Schema } from "effect"
const schema = Schema.Array(Schema.String)
const result = Schema.decodeUnknownSync(schema)(["a", "b", "c"])
console.log(result)
// [ 'a', 'b', 'c' ]
Array(value: V extends Schema.Constraintvalue)
const const separator: stringseparator = options: | {
readonly separator?: string | undefined
}
| undefined
options?.separator?: string | undefinedseparator ?? ","
const const arrayString: Schema.compose<
Schema.$Array<V>,
Schema.decodeTo<
Schema.$Array<Schema.String>,
Schema.String,
never,
never
>
>
const arrayString: {
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<ReadonlyArray<V['Type']>, readonly []>) => Schema.decodeTo<Schema.$Array<V>, Schema.decodeTo<Schema.$Array<Schema.String>, Schema.String, never, never>, never, never>;
annotateKey: (annotations: Schema.Annotations.Key<ReadonlyArray<V['Type']>>) => Schema.decodeTo<Schema.$Array<V>, Schema.decodeTo<Schema.$Array<Schema.String>, Schema.String, never, never>, never, never>;
check: (checks_0: SchemaAST.Check<ReadonlyArray<V['Type']>>, ...checks: Array<SchemaAST.Check<ReadonlyArray<V['Type']>>>) => Schema.decodeTo<Schema.$Array<V>, Schema.decodeTo<Schema.$Array<Schema.String>, Schema.String, never, never>, never, neve…;
rebuild: (ast: SchemaAST.Arrays) => Schema.decodeTo<Schema.$Array<V>, Schema.decodeTo<Schema.$Array<Schema.String>, Schema.String, never, never>, never, never>;
make: (input: ReadonlyArray<V['~type.make']>, options?: MakeOptions) => ReadonlyArray<V['Type']>;
makeOption: (input: ReadonlyArray<V['~type.make']>, options?: MakeOptions) => Option_.Option<ReadonlyArray<V['Type']>>;
makeEffect: (input: ReadonlyArray<V['~type.make']>, options?: MakeOptions) => Effect.Effect<ReadonlyArray<V['Type']>, 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; <…;
}
arrayString = import SchemaSchema.const String: Stringconst String: {
Rebuild: Rebuild;
Iso: Iso;
ast: Ast;
Type: T;
Encoded: E;
DecodingServices: RD;
EncodingServices: RE;
annotate: (annotations: Schema.Annotations.Bottom<string, readonly []>) => Schema.String;
annotateKey: (annotations: Schema.Annotations.Key<string>) => Schema.String;
check: (checks_0: SchemaAST.Check<string>, ...checks: Array<SchemaAST.Check<string>>) => Schema.String;
rebuild: (ast: SchemaAST.String) => Schema.String;
make: (input: string, options?: MakeOptions) => string;
makeOption: (input: string, options?: MakeOptions) => Option_.Option<string>;
makeEffect: (input: string, options?: MakeOptions) => Effect.Effect<string, 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; <…;
}
Type-level representation of
String
.
Schema for string values. Validates that the input is typeof "string".
String.Pipeable.pipe<Schema.String, Schema.decodeTo<Schema.$Array<Schema.String>, Schema.String, never, never>, Schema.compose<Schema.$Array<V>, Schema.decodeTo<Schema.$Array<Schema.String>, Schema.String, never, never>>>(this: Schema.String, ab: (_: Schema.String) => Schema.decodeTo<Schema.$Array<Schema.String>, Schema.String, never, never>, bc: (_: Schema.decodeTo<Schema.$Array<Schema.String>, Schema.String, never, never>) => Schema.compose<...>): Schema.compose<...> (+21 overloads)pipe(
import SchemaSchema.function decodeTo<Schema.$Array<Schema.String>, Schema.String, never, never>(to: Schema.$Array<Schema.String>, transformation: {
readonly decode: SchemaGetter.Getter<NoInfer<readonly string[]>, string, never>;
readonly encode: SchemaGetter.Getter<string, NoInfer<readonly string[]>, never>;
}): (from: Schema.String) => Schema.decodeTo<Schema.$Array<Schema.String>, Schema.String, never, never> (+1 overload)
Creates a schema that transforms from a source schema to a target schema.
When to use
Use when decoding should change the schema's decoded type or encoded shape,
with an optional custom bidirectional transformation.
Details
Call it with the target schema to and then pipe the source schema from
into the returned function. The resulting schema decodes from
From["Encoded"] to To["Type"] and encodes from To["Type"] back to
From["Encoded"].
When no transformation is provided, SchemaTransformation.passthrough() is
used, so From["Type"] must already be compatible with To["Encoded"].
The resulting schema combines decoding and encoding services from both
schemas and any custom transformation.
Gotchas
In a custom transformation, decode maps From["Type"] to To["Encoded"]
and is used on the encoding path, while encode maps To["Encoded"] to
From["Type"] and is used on the decoding path.
Example (Transforming strings to numbers with a schema transformation)
import { Schema, SchemaGetter } from "effect"
const NumberFromString = Schema.String.pipe(
Schema.decodeTo(
Schema.Number,
{
decode: SchemaGetter.transform((s) => Number(s)),
encode: SchemaGetter.transform((n) => String(n))
}
)
)
const result = Schema.decodeUnknownSync(NumberFromString)("123")
// result: 123
decodeTo(
import SchemaSchema.Array<Schema.String>(self: Schema.String): Schema.$Array<Schema.String>
export Array
Defines a ReadonlyArray schema for a given element schema.
Example (Defining an array of strings)
import { Schema } from "effect"
const schema = Schema.Array(Schema.String)
const result = Schema.decodeUnknownSync(schema)(["a", "b", "c"])
console.log(result)
// [ 'a', 'b', 'c' ]
Array(import SchemaSchema.const String: Stringconst String: {
Rebuild: Rebuild;
Iso: Iso;
ast: Ast;
Type: T;
Encoded: E;
DecodingServices: RD;
EncodingServices: RE;
annotate: (annotations: Schema.Annotations.Bottom<string, readonly []>) => Schema.String;
annotateKey: (annotations: Schema.Annotations.Key<string>) => Schema.String;
check: (checks_0: SchemaAST.Check<string>, ...checks: Array<SchemaAST.Check<string>>) => Schema.String;
rebuild: (ast: SchemaAST.String) => Schema.String;
make: (input: string, options?: MakeOptions) => string;
makeOption: (input: string, options?: MakeOptions) => Option_.Option<string>;
makeEffect: (input: string, options?: MakeOptions) => Effect.Effect<string, 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; <…;
}
Type-level representation of
String
.
Schema for string values. Validates that the input is typeof "string".
String),
{
decode: SchemaGetter.Getter<
ReadonlyArray<string>,
string,
never
>
(property) decode: {
run: (input: Option.Option<E>, options: SchemaAST.ParseOptions) => Effect.Effect<Option.Option<T>, SchemaIssue.Issue, R>;
map: (f: (t: ReadonlyArray<string>) => T2) => SchemaGetter.Getter<T2, string, never>;
compose: (other: SchemaGetter.Getter<T2, ReadonlyArray<string>, R2>) => SchemaGetter.Getter<T2, string, R2>;
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; <…;
}
decode: import SchemaGetterSchemaGetter.function split<
E extends string
>(options?: {
readonly separator?: string | undefined
}): Getter<ReadonlyArray<string>, E>
Splits a string into an array of strings by a separator.
When to use
Use when you need a schema getter to split a present encoded string
containing a delimited list, such as CSV values.
Details
The getter is pure and never fails. It splits by separator (default ,).
An empty string produces an empty array, not [""].
Example (Splitting a comma-separated string)
import { SchemaGetter } from "effect"
const splitComma = SchemaGetter.split<string>()
// "a,b,c" -> ["a", "b", "c"]
// "" -> []
split(options: | {
readonly separator?: string | undefined
}
| undefined
options),
encode: SchemaGetter.Getter<
string,
ReadonlyArray<string>,
never
>
(property) encode: {
run: (input: Option.Option<E>, options: SchemaAST.ParseOptions) => Effect.Effect<Option.Option<T>, SchemaIssue.Issue, R>;
map: (f: (t: string) => T2) => SchemaGetter.Getter<T2, ReadonlyArray<string>, never>;
compose: (other: SchemaGetter.Getter<T2, string, R2>) => SchemaGetter.Getter<T2, ReadonlyArray<string>, R2>;
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; <…;
}
encode: import SchemaGetterSchemaGetter.function transform<T, E>(
f: (e: E) => T
): Getter<T, E>
Creates a getter that applies a pure function to present values.
When to use
Use when you need a schema getter for a pure, infallible transformation
between types.
- Building encode/decode pairs for
Schema.decodeTo.
Details
- This is the most commonly used constructor.
- Transforms
Some(e) to Some(f(e)) and leaves None unchanged.
- Skips
None inputs — only called when a value is present.
- Never fails.
Example (Transforming strings to numbers)
import { Schema, SchemaGetter } from "effect"
const NumberFromString = Schema.String.pipe(
Schema.decodeTo(Schema.Number, {
decode: SchemaGetter.transform((s) => Number(s)),
encode: SchemaGetter.transform((n) => String(n))
})
)
transform((input: readonly string[]input: interface ReadonlyArray<T>ReadonlyArray<string>) => input: readonly string[]input.ReadonlyArray<string>.join(separator?: string): stringAdds all the elements of an array separated by the specified separator string.
join(const separator: stringseparator))
}
),
import SchemaSchema.function decodeTo<Schema.$Array<V>>(to: Schema.$Array<V>): <From>(from: From) => Schema.compose<Schema.$Array<V>, From> (+1 overload)Creates a schema that transforms from a source schema to a target schema.
When to use
Use when decoding should change the schema's decoded type or encoded shape,
with an optional custom bidirectional transformation.
Details
Call it with the target schema to and then pipe the source schema from
into the returned function. The resulting schema decodes from
From["Encoded"] to To["Type"] and encodes from To["Type"] back to
From["Encoded"].
When no transformation is provided, SchemaTransformation.passthrough() is
used, so From["Type"] must already be compatible with To["Encoded"].
The resulting schema combines decoding and encoding services from both
schemas and any custom transformation.
Gotchas
In a custom transformation, decode maps From["Type"] to To["Encoded"]
and is used on the encoding path, while encode maps To["Encoded"] to
From["Type"] and is used on the decoding path.
Example (Transforming strings to numbers with a schema transformation)
import { Schema, SchemaGetter } from "effect"
const NumberFromString = Schema.String.pipe(
Schema.decodeTo(
Schema.Number,
{
decode: SchemaGetter.transform((s) => Number(s)),
encode: SchemaGetter.transform((n) => String(n))
}
)
)
const result = Schema.decodeUnknownSync(NumberFromString)("123")
// result: 123
decodeTo(const array: Schema.$Array<V>const array: {
Type: ReadonlyArray<S["Type"]>;
Encoded: ReadonlyArray<S["Encoded"]>;
DecodingServices: S["DecodingServices"];
EncodingServices: S["EncodingServices"];
Iso: ReadonlyArray<S["Iso"]>;
value: S;
Rebuild: Rebuild;
ast: Ast;
annotate: (annotations: Schema.Annotations.Bottom<ReadonlyArray<V['Type']>, readonly []>) => Schema.$Array<V>;
annotateKey: (annotations: Schema.Annotations.Key<ReadonlyArray<V['Type']>>) => Schema.$Array<V>;
check: (checks_0: SchemaAST.Check<ReadonlyArray<V['Type']>>, ...checks: Array<SchemaAST.Check<ReadonlyArray<V['Type']>>>) => Schema.$Array<V>;
rebuild: (ast: SchemaAST.Arrays) => Schema.$Array<V>;
make: (input: ReadonlyArray<V['~type.make']>, options?: MakeOptions) => ReadonlyArray<V['Type']>;
makeOption: (input: ReadonlyArray<V['~type.make']>, options?: MakeOptions) => Option_.Option<ReadonlyArray<V['Type']>>;
makeEffect: (input: ReadonlyArray<V['~type.make']>, options?: MakeOptions) => Effect.Effect<ReadonlyArray<V['Type']>, 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; <…;
}
array)
)
return import SchemaSchema.function Union<
Members extends ReadonlyArray<Constraint>
>(
members: Members,
options?: { mode?: "anyOf" | "oneOf" }
): Union<Members>
Creates a union schema from an array of member schemas. Members are tested in
order; the first match is returned.
Details
Optionally, specify mode:
"anyOf" (default) — matches if any member matches.
"oneOf" — matches if exactly one member matches.
Example (Defining a string or number union)
import { Schema } from "effect"
const schema = Schema.Union([Schema.String, Schema.Number])
Schema.decodeUnknownSync(schema)("hello") // "hello"
Schema.decodeUnknownSync(schema)(42) // 42
Union([const arrayString: Schema.compose<
Schema.$Array<V>,
Schema.decodeTo<
Schema.$Array<Schema.String>,
Schema.String,
never,
never
>
>
const arrayString: {
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<ReadonlyArray<V['Type']>, readonly []>) => Schema.decodeTo<Schema.$Array<V>, Schema.decodeTo<Schema.$Array<Schema.String>, Schema.String, never, never>, never, never>;
annotateKey: (annotations: Schema.Annotations.Key<ReadonlyArray<V['Type']>>) => Schema.decodeTo<Schema.$Array<V>, Schema.decodeTo<Schema.$Array<Schema.String>, Schema.String, never, never>, never, never>;
check: (checks_0: SchemaAST.Check<ReadonlyArray<V['Type']>>, ...checks: Array<SchemaAST.Check<ReadonlyArray<V['Type']>>>) => Schema.decodeTo<Schema.$Array<V>, Schema.decodeTo<Schema.$Array<Schema.String>, Schema.String, never, never>, never, neve…;
rebuild: (ast: SchemaAST.Arrays) => Schema.decodeTo<Schema.$Array<V>, Schema.decodeTo<Schema.$Array<Schema.String>, Schema.String, never, never>, never, never>;
make: (input: ReadonlyArray<V['~type.make']>, options?: MakeOptions) => ReadonlyArray<V['Type']>;
makeOption: (input: ReadonlyArray<V['~type.make']>, options?: MakeOptions) => Option_.Option<ReadonlyArray<V['Type']>>;
makeEffect: (input: ReadonlyArray<V['~type.make']>, options?: MakeOptions) => Effect.Effect<ReadonlyArray<V['Type']>, 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; <…;
}
arrayString, const array: Schema.$Array<V>const array: {
Type: ReadonlyArray<S["Type"]>;
Encoded: ReadonlyArray<S["Encoded"]>;
DecodingServices: S["DecodingServices"];
EncodingServices: S["EncodingServices"];
Iso: ReadonlyArray<S["Iso"]>;
value: S;
Rebuild: Rebuild;
ast: Ast;
annotate: (annotations: Schema.Annotations.Bottom<ReadonlyArray<V['Type']>, readonly []>) => Schema.$Array<V>;
annotateKey: (annotations: Schema.Annotations.Key<ReadonlyArray<V['Type']>>) => Schema.$Array<V>;
check: (checks_0: SchemaAST.Check<ReadonlyArray<V['Type']>>, ...checks: Array<SchemaAST.Check<ReadonlyArray<V['Type']>>>) => Schema.$Array<V>;
rebuild: (ast: SchemaAST.Arrays) => Schema.$Array<V>;
make: (input: ReadonlyArray<V['~type.make']>, options?: MakeOptions) => ReadonlyArray<V['Type']>;
makeOption: (input: ReadonlyArray<V['~type.make']>, options?: MakeOptions) => Option_.Option<ReadonlyArray<V['Type']>>;
makeEffect: (input: ReadonlyArray<V['~type.make']>, options?: MakeOptions) => Effect.Effect<ReadonlyArray<V['Type']>, 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; <…;
}
array])
}