<T>(
filter: (
input: T,
ast: SchemaAST.AST,
options: SchemaAST.ParseOptions
) => FilterOutput,
annotations?: Annotations.Filter | undefined,
abort?: boolean
): SchemaAST.Filter<T>Creates a custom validation filter from a predicate function.
Details
The predicate receives the decoded input value, the schema AST, and parse
options, and returns a FilterOutput. Non-success outputs are normalized into
schema issues. The annotations parameter annotates the filter itself; with
the default formatter, failures use message first, expected second, and
<filter> when neither is provided.
When abort is true, parsing stops after this filter fails instead of
collecting later check failures.
Example (Reporting failure at a nested path)
import { Schema } from "effect"
const schema = Schema.Struct({ password: Schema.String, confirmPassword: Schema.String }).check(
Schema.makeFilter((o) =>
o.password === o.confirmPassword
? undefined
: { path: ["password"], issue: "password and confirmPassword must match" }
)
)
console.log(String(Schema.decodeUnknownExit(schema)({ password: "123456", confirmPassword: "1234567" })))
// Failure(Cause([Fail(SchemaError: password and confirmPassword must match
// at ["password"])]))Example (Reporting multiple failures at once)
import { Schema } from "effect"
const schema = Schema.Struct({ a: Schema.Finite, b: Schema.Finite, c: Schema.Finite }).check(
Schema.makeFilter((o) => {
const issues: Array<Schema.FilterIssue> = []
if (o.a > 0) {
if (o.b <= 0) issues.push({ path: ["b"], issue: "b must be greater than 0" })
if (o.c <= 0) issues.push({ path: ["c"], issue: "c must be greater than 0" })
}
return issues
})
)
console.log(String(Schema.decodeUnknownExit(schema)({ a: 1, b: 0, c: 0 })))
// Failure(Cause([Fail(SchemaError: b must be greater than 0
// at ["b"]
// c must be greater than 0
// at ["c"])]))export const const makeFilter: <T>(
filter: (
input: T,
ast: SchemaAST.AST,
options: SchemaAST.ParseOptions
) => FilterOutput,
annotations?: Annotations.Filter | undefined,
abort?: boolean
) => SchemaAST.Filter<T>
Creates a custom validation filter from a predicate function.
Details
The predicate receives the decoded input value, the schema AST, and parse
options, and returns a FilterOutput. Non-success outputs are normalized into
schema issues. The annotations parameter annotates the filter itself; with
the default formatter, failures use message first, expected second, and
<filter> when neither is provided.
When abort is true, parsing stops after this filter fails instead of
collecting later check failures.
Example (Reporting failure at a nested path)
import { Schema } from "effect"
const schema = Schema.Struct({ password: Schema.String, confirmPassword: Schema.String }).check(
Schema.makeFilter((o) =>
o.password === o.confirmPassword
? undefined
: { path: ["password"], issue: "password and confirmPassword must match" }
)
)
console.log(String(Schema.decodeUnknownExit(schema)({ password: "123456", confirmPassword: "1234567" })))
// Failure(Cause([Fail(SchemaError: password and confirmPassword must match
// at ["password"])]))
Example (Reporting multiple failures at once)
import { Schema } from "effect"
const schema = Schema.Struct({ a: Schema.Finite, b: Schema.Finite, c: Schema.Finite }).check(
Schema.makeFilter((o) => {
const issues: Array<Schema.FilterIssue> = []
if (o.a > 0) {
if (o.b <= 0) issues.push({ path: ["b"], issue: "b must be greater than 0" })
if (o.c <= 0) issues.push({ path: ["c"], issue: "c must be greater than 0" })
}
return issues
})
)
console.log(String(Schema.decodeUnknownExit(schema)({ a: 1, b: 0, c: 0 })))
// Failure(Cause([Fail(SchemaError: b must be greater than 0
// at ["b"]
// c must be greater than 0
// at ["c"])]))
makeFilter: <function (type parameter) T in <T>(filter: (input: T, ast: SchemaAST.AST, options: SchemaAST.ParseOptions) => FilterOutput, annotations?: Annotations.Filter | undefined, abort?: boolean): SchemaAST.Filter<T>T>(
filter: (
input: T,
ast: SchemaAST.AST,
options: SchemaAST.ParseOptions
) => FilterOutput
filter: (input: Tinput: function (type parameter) T in <T>(filter: (input: T, ast: SchemaAST.AST, options: SchemaAST.ParseOptions) => FilterOutput, annotations?: Annotations.Filter | undefined, abort?: boolean): SchemaAST.Filter<T>T, ast: SchemaAST.ASTast: import SchemaASTSchemaAST.type AST = SchemaAST.Declaration | SchemaAST.Null | SchemaAST.Undefined | SchemaAST.Void | SchemaAST.Never | SchemaAST.Unknown | SchemaAST.Any | SchemaAST.String | SchemaAST.Number | SchemaAST.Boolean | SchemaAST.BigInt | SchemaAST.Symbol | SchemaAST.Literal | SchemaAST.UniqueSymbol | SchemaAST.ObjectKeyword | SchemaAST.Enum | SchemaAST.TemplateLiteral | SchemaAST.Arrays | SchemaAST.Objects | SchemaAST.Union<...> | SchemaAST.SuspendDiscriminated union of all AST node types.
Details
Every Schema has an .ast property of this type. Use the guard functions
(
isString
,
isObjects
, etc.) to narrow to a specific variant,
then access variant-specific fields.
- All variants share the
Base
fields:
annotations, checks,
encoding, context.
- Discriminate on the
_tag field (e.g. "String", "Objects", "Union").
AST, options: SchemaAST.ParseOptions(parameter) options: {
errors: "first" | "all" | undefined;
onExcessProperty: "ignore" | "error" | "preserve" | undefined;
propertyOrder: "none" | "original" | undefined;
disableChecks: boolean | undefined;
concurrency: number | "unbounded" | undefined;
}
options: import SchemaASTSchemaAST.ParseOptions) => type FilterOutput =
| boolean
| FilterIssue
| readonly FilterIssue[]
| undefined
The value a filter predicate (see
makeFilter
) may return.
Details
Each shape is normalized into an
SchemaIssue.Issue
(or undefined for
success) before being attached to the parse result:
undefined: success. The input satisfies the filter.
true: success. Equivalent to undefined, useful when the predicate is
a plain boolean expression.
false: generic failure. Produces an
SchemaIssue.InvalidValue
wrapping
the input, with no custom message.
FilterIssue
: a single failure. See
FilterIssue
for the
shapes (string,
SchemaIssue.Issue
, or { path, issue }).
ReadonlyArray<FilterIssue>: several failures reported together. An
empty array is treated as success; a single-element array is equivalent
to returning that element directly; otherwise the entries are grouped
into an
SchemaIssue.Composite
.
FilterOutput,
annotations: Annotations.Filter | undefinedannotations?: Annotations.interface Annotations.FilterAnnotations for filter schema nodes (created via Schema.filter). Extends
Augment
with an optional error message, identifier, and metadata.
Filters are intentionally non-parametric to keep them covariant.
Filter | undefined,
abort: boolean | undefinedabort?: boolean
) => import SchemaASTSchemaAST.class Filter<in E>class Filter {
_tag: 'Filter';
run: (input: E, self: AST, options: ParseOptions) => SchemaIssue.Issue | undefined;
annotations: Schema.Annotations.Filter | undefined;
aborted: boolean;
annotate: (annotations: Schema.Annotations.Filter) => Filter<E>;
abort: () => Filter<E>;
and: (other: Check<E>, annotations?: Schema.Annotations.Filter) => FilterGroup<E>;
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; <…;
}
Represents a single validation check attached to an AST node.
Details
run — the validation function. Returns undefined on success, or an
Issue on failure.
annotations — optional filter-level metadata (expected message, meta
tags, arbitrary constraint hints).
aborted — when true, parsing stops immediately after this filter
fails (no further checks run).
Use .annotate() to add metadata and .abort() to mark as aborting.
Combine with another check via .and() to form a
FilterGroup
.
Filter<function (type parameter) T in <T>(filter: (input: T, ast: SchemaAST.AST, options: SchemaAST.ParseOptions) => FilterOutput, annotations?: Annotations.Filter | undefined, abort?: boolean): SchemaAST.Filter<T>T> = import SchemaASTSchemaAST.function makeFilter<T>(
filter: (
input: T,
ast: AST,
options: ParseOptions
) => Schema.FilterOutput,
annotations?:
| Schema.Annotations.Filter
| undefined,
aborted?: boolean
): Filter<T>
makeFilter