<S extends Schema.ConstraintEncoder<unknown>>(
schema: S,
options?: SchemaAST.ParseOptions
): (
input: unknown,
options?: SchemaAST.ParseOptions
) => Result.Result<S["Encoded"], SchemaIssue.Issue>Creates an encoder for unknown input that reports failure safely as a
Result.
When to use
Use when encoding values from an unknown or dynamically typed boundary
synchronously, and you want SchemaIssue.Issue failures returned as Result
data.
Details
The returned function produces Result.succeed with the schema's Encoded
value on success or Result.fail with a SchemaIssue.Issue on encoding
failure.
Gotchas
This adapter runs synchronously. Causes made entirely of schema issues become
Result.fail, but causes that contain defects, interruptions, or asynchronous
work at this synchronous boundary throw instead.
export function function encodeUnknownResult<
S extends Schema.ConstraintEncoder<unknown>
>(
schema: S,
options?: SchemaAST.ParseOptions
): (
input: unknown,
options?: SchemaAST.ParseOptions
) => Result.Result<
S["Encoded"],
SchemaIssue.Issue
>
Creates an encoder for unknown input that reports failure safely as a
Result.
When to use
Use when encoding values from an unknown or dynamically typed boundary
synchronously, and you want SchemaIssue.Issue failures returned as Result
data.
Details
The returned function produces Result.succeed with the schema's Encoded
value on success or Result.fail with a SchemaIssue.Issue on encoding
failure.
Gotchas
This adapter runs synchronously. Causes made entirely of schema issues become
Result.fail, but causes that contain defects, interruptions, or asynchronous
work at this synchronous boundary throw instead.
encodeUnknownResult<function (type parameter) S in encodeUnknownResult<S extends Schema.ConstraintEncoder<unknown>>(schema: S, options?: SchemaAST.ParseOptions): (input: unknown, options?: SchemaAST.ParseOptions) => Result.Result<S["Encoded"], SchemaIssue.Issue>S extends import SchemaSchema.interface ConstraintEncoder<out E, out RE = never>Lightweight structural constraint for APIs that need encoder type views but
do not need the full schema protocol.
When to use
Use when you need to preserve a schema's encoded type and encoding services,
but the API does not constrain the decoded type, decoding services, or call
schema methods such as annotate, check, rebuild, make, or
makeEffect.
ConstraintEncoder<unknown>>(
schema: S extends Schema.ConstraintEncoder<unknown>schema: function (type parameter) S in encodeUnknownResult<S extends Schema.ConstraintEncoder<unknown>>(schema: S, options?: SchemaAST.ParseOptions): (input: unknown, options?: SchemaAST.ParseOptions) => Result.Result<S["Encoded"], SchemaIssue.Issue>S,
options: SchemaAST.ParseOptionsoptions?: import SchemaASTSchemaAST.ParseOptions
): (input: unknowninput: unknown, options: SchemaAST.ParseOptionsoptions?: import SchemaASTSchemaAST.ParseOptions) => import ResultResult.type Result<A, E = never> = Result.Success<A, E> | Result.Failure<A, E>A value that is either Success<A, E> or Failure<A, E>.
When to use
Use when both success and failure should remain available as data and
Option would lose failure information.
Details
- Use
succeed
/
fail
to construct
- Use
match
to fold both branches
- Use
isSuccess
/
isFailure
to narrow the type
E defaults to never, so Result<number> means a result that cannot fail.
Example (Creating and matching a Result)
import { Result } from "effect"
const success = Result.succeed(42)
const failure = Result.fail("something went wrong")
const message = Result.match(success, {
onSuccess: (value) => `Success: ${value}`,
onFailure: (error) => `Error: ${error}`
})
console.log(message)
// Output: "Success: 42"
Namespace containing type-level utilities for extracting the inner types
of a Result.
Example (Extracting inner types)
import type { Result } from "effect"
type R = Result.Result<number, string>
// number
type A = Result.Result.Success<R>
// string
type E = Result.Result.Failure<R>
Result<function (type parameter) S in encodeUnknownResult<S extends Schema.ConstraintEncoder<unknown>>(schema: S, options?: SchemaAST.ParseOptions): (input: unknown, options?: SchemaAST.ParseOptions) => Result.Result<S["Encoded"], SchemaIssue.Issue>S["Encoded"], import SchemaIssueSchemaIssue.type Issue =
| SchemaIssue.Leaf
| SchemaIssue.Filter
| SchemaIssue.Encoding
| SchemaIssue.Pointer
| SchemaIssue.Composite
| SchemaIssue.AnyOf
The root discriminated union of all validation error nodes.
When to use
Use when typing the error channel in Effect<A, Issue, R> results from
schema parsing, or when writing custom formatters or issue-tree walkers.
Details
Every node has a _tag field for pattern-matching. The union includes both
terminal
Leaf
types and composite types that wrap inner issues:
Filter
,
Encoding
,
Pointer
,
Composite
,
AnyOf
. All Issue instances have a toString() that delegates to
the default formatter, so String(issue) produces a human-readable message.
Issue> {
return function asResult<T, E, R>(
parser: (
input: E,
options?: SchemaAST.ParseOptions
) => Effect.Effect<T, SchemaIssue.Issue, R>
): (
input: E,
options?: SchemaAST.ParseOptions
) => Result.Result<T, SchemaIssue.Issue>
asResult(function encodeUnknownEffect<
S extends Schema.Constraint
>(
schema: S,
options?: SchemaAST.ParseOptions
): (
input: unknown,
options?: SchemaAST.ParseOptions
) => Effect.Effect<
S["Encoded"],
SchemaIssue.Issue,
S["EncodingServices"]
>
Creates an effectful encoder for unknown input.
When to use
Use when you need to encode untyped boundary input in an Effect whose
failure channel is SchemaIssue.Issue, while preserving service
requirements.
Details
The returned function succeeds with the schema's Encoded value or fails with a
SchemaIssue.Issue. Encoding service requirements are preserved in the returned
Effect. Parse options may be provided when creating the encoder and overridden
when applying it.
encodeUnknownEffect(schema: S extends Schema.ConstraintEncoder<unknown>schema, options: SchemaAST.ParseOptionsoptions))
}