NonEmptyArray<S>Type-level representation returned by NonEmptyArray.
export interface interface NonEmptyArray<S extends Constraint>Type-level representation returned by
NonEmptyArray
.
Defines a non-empty ReadonlyArray schema — at least one element required.
Type is readonly [T, ...T[]].
Example (Defining a non-empty array of numbers)
import { Schema } from "effect"
const schema = Schema.NonEmptyArray(Schema.Number)
Schema.decodeUnknownSync(schema)([1, 2, 3]) // ok
Schema.decodeUnknownSync(schema)([]) // throws
NonEmptyArray<function (type parameter) S in NonEmptyArray<S extends Constraint>S extends Constraint> extends
interface BottomLazy<out Ast extends SchemaAST.AST, out Rebuild extends Top, in out TypeParameters extends ReadonlyArray<Constraint> = readonly [], out TypeMutability extends Mutability = "readonly", out TypeOptionality extends Optionality = "required", out TypeConstructorDefault extends ConstructorDefault = "no-default", out EncodedMutability extends Mutability = "readonly", out EncodedOptionality extends Optionality = "required">Lazy Bottom variant for schema implementations that compute their public
views on demand.
When to use
Use as an implementation base for schema interfaces that must expose
Bottom behavior without forcing TypeScript to eagerly evaluate expensive
Type, Encoded, or service views.
Details
The laziness is purely type-level; runtime behavior is unchanged.
BottomLazy keeps the structural operations inherited from Bottom, but
erases the expensive schema views to unknown. Concrete schema interfaces can
then redeclare the precise views they expose. This keeps wide schemas such as
Struct and Union cheaper when generic code reads a single view, while
preserving their exact public types.
BottomLazy<
import SchemaASTSchemaAST.class Arraysclass Arrays {
_tag: 'Arrays';
isMutable: boolean;
elements: ReadonlyArray<AST>;
rest: ReadonlyArray<AST>;
encodingChecks: Checks | undefined;
getParser: (recur: (ast: AST) => SchemaParser.Parser) => SchemaParser.Parser;
_rebuild: (recur: (ast: AST) => AST, checks: Checks | undefined, encodingChecks: Checks | undefined) => Arrays;
recur: (recur: (ast: AST) => AST) => Arrays;
flip: (recur: (ast: AST) => AST) => Arrays;
getExpected: () => string;
annotations: Schema.Annotations.Annotations | undefined;
checks: Checks | undefined;
encoding: Encoding | undefined;
context: Context | undefined;
toString: () => string;
}
AST node for array-like types — both tuples and arrays.
When to use
Use when constructing or inspecting AST nodes for tuple or array-like schemas,
including rest elements.
Details
elements — positional element types (tuple elements). An element is
optional if its
Context.isOptional
is true.
rest — the rest/variadic element types. When non-empty, the first
entry is the "spread" type (e.g. ...Array<string>), and subsequent
entries are trailing positional elements after the spread.
isMutable — whether the resulting array is readonly (false) or
mutable (true).
Gotchas
Construction enforces TypeScript ordering rules: a required element
cannot follow an optional one, and an optional element cannot follow a
rest element.
Example (Inspecting a tuple AST)
import { Schema, SchemaAST } from "effect"
const schema = Schema.Tuple([Schema.String, Schema.Number])
const ast = schema.ast
if (SchemaAST.isArrays(ast)) {
console.log(ast.elements.length) // 2
console.log(ast.rest.length) // 0
}
Arrays,
interface NonEmptyArray<S extends Constraint>Type-level representation returned by
NonEmptyArray
.
Defines a non-empty ReadonlyArray schema — at least one element required.
Type is readonly [T, ...T[]].
Example (Defining a non-empty array of numbers)
import { Schema } from "effect"
const schema = Schema.NonEmptyArray(Schema.Number)
Schema.decodeUnknownSync(schema)([1, 2, 3]) // ok
Schema.decodeUnknownSync(schema)([]) // throws
NonEmptyArray<function (type parameter) S in NonEmptyArray<S extends Constraint>S>
>
{
readonly "Type": readonly [function (type parameter) S in NonEmptyArray<S extends Constraint>S["Type"], ...interface Array<T>Array<function (type parameter) S in NonEmptyArray<S extends Constraint>S["Type"]>]
readonly "Encoded": readonly [function (type parameter) S in NonEmptyArray<S extends Constraint>S["Encoded"], ...interface Array<T>Array<function (type parameter) S in NonEmptyArray<S extends Constraint>S["Encoded"]>]
readonly "DecodingServices": function (type parameter) S in NonEmptyArray<S extends Constraint>S["DecodingServices"]
readonly "EncodingServices": function (type parameter) S in NonEmptyArray<S extends Constraint>S["EncodingServices"]
readonly "~type.make.in": readonly [function (type parameter) S in NonEmptyArray<S extends Constraint>S["~type.make"], ...interface Array<T>Array<function (type parameter) S in NonEmptyArray<S extends Constraint>S["~type.make"]>]
readonly "~type.make": readonly [function (type parameter) S in NonEmptyArray<S extends Constraint>S["~type.make"], ...interface Array<T>Array<function (type parameter) S in NonEmptyArray<S extends Constraint>S["~type.make"]>]
readonly "Iso": readonly [function (type parameter) S in NonEmptyArray<S extends Constraint>S["Iso"], ...interface Array<T>Array<function (type parameter) S in NonEmptyArray<S extends Constraint>S["Iso"]>]
readonly NonEmptyArray<S extends Constraint>.value: S extends Constraintvalue: function (type parameter) S in NonEmptyArray<S extends Constraint>S
}
interface NonEmptyArrayLambda extends Lambda {
<function (type parameter) S in <S extends Constraint>(self: S): NonEmptyArray<S>S extends Constraint>(self: S extends Constraintself: function (type parameter) S in <S extends Constraint>(self: S): NonEmptyArray<S>S): interface NonEmptyArray<S extends Constraint>Type-level representation returned by
NonEmptyArray
.
Defines a non-empty ReadonlyArray schema — at least one element required.
Type is readonly [T, ...T[]].
Example (Defining a non-empty array of numbers)
import { Schema } from "effect"
const schema = Schema.NonEmptyArray(Schema.Number)
Schema.decodeUnknownSync(schema)([1, 2, 3]) // ok
Schema.decodeUnknownSync(schema)([]) // throws
NonEmptyArray<function (type parameter) S in <S extends Constraint>(self: S): NonEmptyArray<S>S>
readonly "~lambda.out": this["~lambda.in"] extends Constraint ? interface NonEmptyArray<S extends Constraint>Type-level representation returned by
NonEmptyArray
.
Defines a non-empty ReadonlyArray schema — at least one element required.
Type is readonly [T, ...T[]].
Example (Defining a non-empty array of numbers)
import { Schema } from "effect"
const schema = Schema.NonEmptyArray(Schema.Number)
Schema.decodeUnknownSync(schema)([1, 2, 3]) // ok
Schema.decodeUnknownSync(schema)([]) // throws
NonEmptyArray<this["~lambda.in"]> : never
}
/**
* Defines a non-empty `ReadonlyArray` schema — at least one element required.
* Type is `readonly [T, ...T[]]`.
*
* **Example** (Defining a non-empty array of numbers)
*
* ```ts
* import { Schema } from "effect"
*
* const schema = Schema.NonEmptyArray(Schema.Number)
*
* Schema.decodeUnknownSync(schema)([1, 2, 3]) // ok
* Schema.decodeUnknownSync(schema)([]) // throws
* ```
*
* @category constructors
* @since 3.10.0
*/
export const const NonEmptyArray: NonEmptyArrayLambdaType-level representation returned by
NonEmptyArray
.
Defines a non-empty ReadonlyArray schema — at least one element required.
Type is readonly [T, ...T[]].
Example (Defining a non-empty array of numbers)
import { Schema } from "effect"
const schema = Schema.NonEmptyArray(Schema.Number)
Schema.decodeUnknownSync(schema)([1, 2, 3]) // ok
Schema.decodeUnknownSync(schema)([]) // throws
NonEmptyArray = import Struct_Struct_.const lambda: <NonEmptyArrayLambda>(
f: (a: Constraint) => NonEmptyArray<Constraint>
) => NonEmptyArrayLambda
Wraps a plain function as a
Lambda
value so it can be used with
When to use
Use to create a typed lambda for struct mapping APIs that need type-level
input and output tracking.
Details
The type parameter L encodes both the input and output types at the type
level, allowing the compiler to track how struct value types change. At
runtime, the returned value is the same function; lambda only adjusts the
type.
Example (Wrapping values in arrays)
import { pipe, Struct } from "effect"
interface AsArray extends Struct.Lambda {
<A>(self: A): Array<A>
readonly "~lambda.out": Array<this["~lambda.in"]>
}
const asArray = Struct.lambda<AsArray>((a) => [a])
const result = pipe({ x: 1, y: "hello" }, Struct.map(asArray))
console.log(result) // { x: [1], y: ["hello"] }
lambda<NonEmptyArrayLambda>((schema: Constraint(parameter) schema: {
ast: SchemaAST.AST;
Type: unknown;
Encoded: unknown;
DecodingServices: unknown;
EncodingServices: unknown;
Iso: unknown;
}
schema) =>
const make: <S extends Constraint>(
ast: S["ast"],
options?: object
) => S
Creates a schema from an AST (Abstract Syntax Tree) node.
Details
This is the fundamental constructor for all schemas in the Effect Schema
library. It takes an AST node and wraps it in a fully-typed schema that
preserves all type information and provides the complete schema API.
The make function is used internally to create all primitive schemas like
String, Number, Boolean, etc., as well as more complex schemas. It's
the bridge between the untyped AST representation and the strongly-typed
schema.
make(new import SchemaASTSchemaAST.constructor Arrays(isMutable: boolean, elements: ReadonlyArray<SchemaAST.AST>, rest: ReadonlyArray<SchemaAST.AST>, annotations?: Annotations.Annotations, checks?: SchemaAST.Checks, encoding?: SchemaAST.Encoding, context?: SchemaAST.Context, encodingChecks?: SchemaAST.Checks): SchemaAST.ArraysAST node for array-like types — both tuples and arrays.
When to use
Use when constructing or inspecting AST nodes for tuple or array-like schemas,
including rest elements.
Details
elements — positional element types (tuple elements). An element is
optional if its
Context.isOptional
is true.
rest — the rest/variadic element types. When non-empty, the first
entry is the "spread" type (e.g. ...Array<string>), and subsequent
entries are trailing positional elements after the spread.
isMutable — whether the resulting array is readonly (false) or
mutable (true).
Gotchas
Construction enforces TypeScript ordering rules: a required element
cannot follow an optional one, and an optional element cannot follow a
rest element.
Example (Inspecting a tuple AST)
import { Schema, SchemaAST } from "effect"
const schema = Schema.Tuple([Schema.String, Schema.Number])
const ast = schema.ast
if (SchemaAST.isArrays(ast)) {
console.log(ast.elements.length) // 2
console.log(ast.rest.length) // 0
}
Arrays(false, [schema: Constraint(parameter) schema: {
ast: SchemaAST.AST;
Type: unknown;
Encoded: unknown;
DecodingServices: unknown;
EncodingServices: unknown;
Iso: unknown;
}
schema.Constraint["ast"]: SchemaAST.ASTast], [schema: Constraint(parameter) schema: {
ast: SchemaAST.AST;
Type: unknown;
Encoded: unknown;
DecodingServices: unknown;
EncodingServices: unknown;
Iso: unknown;
}
schema.Constraint["ast"]: SchemaAST.ASTast]), { value: Constraint(property) value: {
ast: SchemaAST.AST;
Type: unknown;
Encoded: unknown;
DecodingServices: unknown;
EncodingServices: unknown;
Iso: unknown;
}
value: schema: Constraint(parameter) schema: {
ast: SchemaAST.AST;
Type: unknown;
Encoded: unknown;
DecodingServices: unknown;
EncodingServices: unknown;
Iso: unknown;
}
schema })
)