Skip to content

Error Messages

By default, when a parsing error occurs, the system automatically generates an informative message based on the schema’s structure and the nature of the error (see TreeFormatter for more informations). For example, if a required property is missing or a data type does not match, the error message will clearly state the expectation versus the actual input.

Example (Type Mismatch)

import {
import Schema
Schema
} from "effect"
const
const Person: Schema.Struct<{
name: typeof Schema.String;
age: typeof Schema.Number;
}>
Person
=
import Schema
Schema
.
function Struct<{
name: typeof Schema.String;
age: typeof Schema.Number;
}>(fields: {
name: typeof Schema.String;
age: typeof Schema.Number;
}): Schema.Struct<{
name: typeof Schema.String;
age: typeof Schema.Number;
}> (+1 overload)

@since3.10.0

Struct
({
name: typeof Schema.String
name
:
import Schema
Schema
.
class String
export String

@since3.10.0

String
,
age: typeof Schema.Number
age
:
import Schema
Schema
.
class Number
export Number

@since3.10.0

Number
})
import Schema
Schema
.
decodeUnknownSync<{
readonly name: string;
readonly age: number;
}, {
readonly name: string;
readonly age: number;
}>(schema: Schema.Schema<{
readonly name: string;
readonly age: number;
}, {
readonly name: string;
readonly age: number;
}, never>, options?: ParseOptions): (u: unknown, overrideOptions?: ParseOptions) => {
readonly name: string;
readonly age: number;
}
export decodeUnknownSync

@throwsParseError

@since3.10.0

decodeUnknownSync
(
const Person: Schema.Struct<{
name: typeof Schema.String;
age: typeof Schema.Number;
}>
Person
)(null)
// Output: ParseError: Expected { readonly name: string; readonly age: number }, actual null

Example (Missing Properties)

import {
import Schema
Schema
} from "effect"
const
const Person: Schema.Struct<{
name: typeof Schema.String;
age: typeof Schema.Number;
}>
Person
=
import Schema
Schema
.
function Struct<{
name: typeof Schema.String;
age: typeof Schema.Number;
}>(fields: {
name: typeof Schema.String;
age: typeof Schema.Number;
}): Schema.Struct<{
name: typeof Schema.String;
age: typeof Schema.Number;
}> (+1 overload)

@since3.10.0

Struct
({
name: typeof Schema.String
name
:
import Schema
Schema
.
class String
export String

@since3.10.0

String
,
age: typeof Schema.Number
age
:
import Schema
Schema
.
class Number
export Number

@since3.10.0

Number
})
import Schema
Schema
.
decodeUnknownSync<{
readonly name: string;
readonly age: number;
}, {
readonly name: string;
readonly age: number;
}>(schema: Schema.Schema<{
readonly name: string;
readonly age: number;
}, {
readonly name: string;
readonly age: number;
}, never>, options?: ParseOptions): (u: unknown, overrideOptions?: ParseOptions) => {
readonly name: string;
readonly age: number;
}
export decodeUnknownSync

@throwsParseError

@since3.10.0

decodeUnknownSync
(
const Person: Schema.Struct<{
name: typeof Schema.String;
age: typeof Schema.Number;
}>
Person
)({}, {
ParseOptions.errors?: "first" | "all" | undefined

The errors option allows you to receive all parsing errors when attempting to parse a value using a schema. By default only the first error is returned, but by setting the errors option to "all", you can receive all errors that occurred during the parsing process. This can be useful for debugging or for providing more comprehensive error messages to the user.

default: "first"

@since3.10.0

errors
: "all" })
/*
throws:
ParseError: { readonly name: string; readonly age: number }
├─ ["name"]
│ └─ is missing
└─ ["age"]
└─ is missing
*/

Example (Incorrect Property Type)

import {
import Schema
Schema
} from "effect"
const
const Person: Schema.Struct<{
name: typeof Schema.String;
age: typeof Schema.Number;
}>
Person
=
import Schema
Schema
.
function Struct<{
name: typeof Schema.String;
age: typeof Schema.Number;
}>(fields: {
name: typeof Schema.String;
age: typeof Schema.Number;
}): Schema.Struct<{
name: typeof Schema.String;
age: typeof Schema.Number;
}> (+1 overload)

@since3.10.0

Struct
({
name: typeof Schema.String
name
:
import Schema
Schema
.
class String
export String

@since3.10.0

String
,
age: typeof Schema.Number
age
:
import Schema
Schema
.
class Number
export Number

@since3.10.0

Number
})
import Schema
Schema
.
decodeUnknownSync<{
readonly name: string;
readonly age: number;
}, {
readonly name: string;
readonly age: number;
}>(schema: Schema.Schema<{
readonly name: string;
readonly age: number;
}, {
readonly name: string;
readonly age: number;
}, never>, options?: ParseOptions): (u: unknown, overrideOptions?: ParseOptions) => {
readonly name: string;
readonly age: number;
}
export decodeUnknownSync

@throwsParseError

@since3.10.0

decodeUnknownSync
(
const Person: Schema.Struct<{
name: typeof Schema.String;
age: typeof Schema.Number;
}>
Person
)(
{
name: null
name
: null,
age: string
age
: "age" },
{
ParseOptions.errors?: "first" | "all" | undefined

The errors option allows you to receive all parsing errors when attempting to parse a value using a schema. By default only the first error is returned, but by setting the errors option to "all", you can receive all errors that occurred during the parsing process. This can be useful for debugging or for providing more comprehensive error messages to the user.

default: "first"

@since3.10.0

errors
: "all" }
)
/*
throws:
ParseError: { readonly name: string; readonly age: number }
├─ ["name"]
│ └─ Expected string, actual null
└─ ["age"]
└─ Expected number, actual "age"
*/

In scenarios where a schema has multiple fields or nested structures, the default error messages can become overly complex and verbose. To address this, you can enhance the clarity and brevity of these messages by utilizing annotations such as identifier, title, and description.

Example (Using Identifiers for Clarity)

import {
import Schema
Schema
} from "effect"
const
const Name: Schema.SchemaClass<string, string, never>
Name
=
import Schema
Schema
.
class String
export String

@since3.10.0

String
.
Annotable<SchemaClass<string, string, never>, string, string, never>.annotations(annotations: Schema.Annotations.GenericSchema<string>): Schema.SchemaClass<string, string, never>

Merges a set of new annotations with existing ones, potentially overwriting any duplicates.

annotations
({
Annotations.Schema<string, readonly []>.identifier?: string
identifier
: "Name" })
const
const Age: Schema.SchemaClass<number, number, never>
Age
=
import Schema
Schema
.
class Number
export Number

@since3.10.0

Number
.
Annotable<SchemaClass<number, number, never>, number, number, never>.annotations(annotations: Schema.Annotations.GenericSchema<number>): Schema.SchemaClass<number, number, never>

Merges a set of new annotations with existing ones, potentially overwriting any duplicates.

annotations
({
Annotations.Schema<A, TypeParameters extends ReadonlyArray<any> = readonly []>.identifier?: string
identifier
: "Age" })
const
const Person: Schema.Struct<{
name: Schema.SchemaClass<string, string, never>;
age: Schema.SchemaClass<number, number, never>;
}>
Person
=
import Schema
Schema
.
function Struct<{
name: Schema.SchemaClass<string, string, never>;
age: Schema.SchemaClass<number, number, never>;
}>(fields: {
name: Schema.SchemaClass<string, string, never>;
age: Schema.SchemaClass<number, number, never>;
}): Schema.Struct<...> (+1 overload)

@since3.10.0

Struct
({
name: Schema.SchemaClass<string, string, never>
name
:
const Name: Schema.SchemaClass<string, string, never>
Name
,
age: Schema.SchemaClass<number, number, never>
age
:
const Age: Schema.SchemaClass<number, number, never>
Age
}).
Struct<{ name: SchemaClass<string, string, never>; age: SchemaClass<number, number, never>; }>.annotations(annotations: Schema.Annotations.Schema<{
readonly name: string;
readonly age: number;
}, readonly []>): Schema.Struct<{
name: Schema.SchemaClass<string, string, never>;
age: Schema.SchemaClass<number, number, never>;
}>

Merges a set of new annotations with existing ones, potentially overwriting any duplicates.

annotations
({
Annotations.Schema<A, TypeParameters extends ReadonlyArray<any> = readonly []>.identifier?: string
identifier
: "Person" })
import Schema
Schema
.
decodeUnknownSync<{
readonly name: string;
readonly age: number;
}, {
readonly name: string;
readonly age: number;
}>(schema: Schema.Schema<{
readonly name: string;
readonly age: number;
}, {
readonly name: string;
readonly age: number;
}, never>, options?: ParseOptions): (u: unknown, overrideOptions?: ParseOptions) => {
readonly name: string;
readonly age: number;
}
export decodeUnknownSync

@throwsParseError

@since3.10.0

decodeUnknownSync
(
const Person: Schema.Struct<{
name: Schema.SchemaClass<string, string, never>;
age: Schema.SchemaClass<number, number, never>;
}>
Person
)(null)
/*
throws:
ParseError: Expected Person, actual null
*/
import Schema
Schema
.
decodeUnknownSync<{
readonly name: string;
readonly age: number;
}, {
readonly name: string;
readonly age: number;
}>(schema: Schema.Schema<{
readonly name: string;
readonly age: number;
}, {
readonly name: string;
readonly age: number;
}, never>, options?: ParseOptions): (u: unknown, overrideOptions?: ParseOptions) => {
readonly name: string;
readonly age: number;
}
export decodeUnknownSync

@throwsParseError

@since3.10.0

decodeUnknownSync
(
const Person: Schema.Struct<{
name: Schema.SchemaClass<string, string, never>;
age: Schema.SchemaClass<number, number, never>;
}>
Person
)({}, {
ParseOptions.errors?: "first" | "all" | undefined

The errors option allows you to receive all parsing errors when attempting to parse a value using a schema. By default only the first error is returned, but by setting the errors option to "all", you can receive all errors that occurred during the parsing process. This can be useful for debugging or for providing more comprehensive error messages to the user.

default: "first"

@since3.10.0

errors
: "all" })
/*
throws:
ParseError: Person
├─ ["name"]
│ └─ is missing
└─ ["age"]
└─ is missing
*/
import Schema
Schema
.
decodeUnknownSync<{
readonly name: string;
readonly age: number;
}, {
readonly name: string;
readonly age: number;
}>(schema: Schema.Schema<{
readonly name: string;
readonly age: number;
}, {
readonly name: string;
readonly age: number;
}, never>, options?: ParseOptions): (u: unknown, overrideOptions?: ParseOptions) => {
readonly name: string;
readonly age: number;
}
export decodeUnknownSync

@throwsParseError

@since3.10.0

decodeUnknownSync
(
const Person: Schema.Struct<{
name: Schema.SchemaClass<string, string, never>;
age: Schema.SchemaClass<number, number, never>;
}>
Person
)(
{
name: null
name
: null,
age: null
age
: null },
{
ParseOptions.errors?: "first" | "all" | undefined

The errors option allows you to receive all parsing errors when attempting to parse a value using a schema. By default only the first error is returned, but by setting the errors option to "all", you can receive all errors that occurred during the parsing process. This can be useful for debugging or for providing more comprehensive error messages to the user.

default: "first"

@since3.10.0

errors
: "all" }
)
/*
throws:
ParseError: Person
├─ ["name"]
│ └─ Expected Name, actual null
└─ ["age"]
└─ Expected Age, actual null
*/

When a refinement fails, the default error message indicates whether the failure occurred in the “from” part or within the predicate defining the refinement:

Example (Refinement Errors)

import {
import Schema
Schema
} from "effect"
const
const Name: Schema.refine<string, Schema.Schema<string, string, never>>
Name
=
import Schema
Schema
.
class NonEmptyString

@since3.10.0

NonEmptyString
.
Annotable<refine<string, Schema<string, string, never>>, string, string, never>.annotations(annotations: Schema.Annotations.GenericSchema<string>): Schema.refine<string, Schema.Schema<string, string, never>>

Merges a set of new annotations with existing ones, potentially overwriting any duplicates.

annotations
({
Annotations.Schema<string, readonly []>.identifier?: string
identifier
: "Name" })
const
const Age: Schema.filter<Schema.Schema<number, number, never>>
Age
=
import Schema
Schema
.
class Positive

@since3.10.0

Positive
.
Pipeable.pipe<typeof Schema.Positive, Schema.filter<Schema.Schema<number, number, never>>>(this: typeof Schema.Positive, ab: (_: typeof Schema.Positive) => Schema.filter<Schema.Schema<number, number, never>>): Schema.filter<...> (+21 overloads)
pipe
(
import Schema
Schema
.
const int: <number>(annotations?: Schema.Annotations.Filter<number, number> | undefined) => <I, R>(self: Schema.Schema<number, I, R>) => Schema.filter<Schema.Schema<number, I, R>>

@since3.10.0

int
({
Annotations.Schema<A, TypeParameters extends ReadonlyArray<any> = readonly []>.identifier?: string
identifier
: "Age" }))
const
const Person: Schema.Struct<{
name: Schema.refine<string, Schema.Schema<string, string, never>>;
age: Schema.filter<Schema.Schema<number, number, never>>;
}>
Person
=
import Schema
Schema
.
function Struct<{
name: Schema.refine<string, Schema.Schema<string, string, never>>;
age: Schema.filter<Schema.Schema<number, number, never>>;
}>(fields: {
name: Schema.refine<string, Schema.Schema<string, string, never>>;
age: Schema.filter<Schema.Schema<number, number, never>>;
}): Schema.Struct<...> (+1 overload)

@since3.10.0

Struct
({
name: Schema.refine<string, Schema.Schema<string, string, never>>
name
:
const Name: Schema.refine<string, Schema.Schema<string, string, never>>
Name
,
age: Schema.filter<Schema.Schema<number, number, never>>
age
:
const Age: Schema.filter<Schema.Schema<number, number, never>>
Age
}).
Struct<{ name: refine<string, Schema<string, string, never>>; age: filter<Schema<number, number, never>>; }>.annotations(annotations: Schema.Annotations.Schema<{
readonly name: string;
readonly age: number;
}, readonly []>): Schema.Struct<{
name: Schema.refine<string, Schema.Schema<string, string, never>>;
age: Schema.filter<...>;
}>

Merges a set of new annotations with existing ones, potentially overwriting any duplicates.

annotations
({
Annotations.Schema<A, TypeParameters extends ReadonlyArray<any> = readonly []>.identifier?: string
identifier
: "Person" })
// From side failure
import Schema
Schema
.
decodeUnknownSync<{
readonly name: string;
readonly age: number;
}, {
readonly name: string;
readonly age: number;
}>(schema: Schema.Schema<{
readonly name: string;
readonly age: number;
}, {
readonly name: string;
readonly age: number;
}, never>, options?: ParseOptions): (u: unknown, overrideOptions?: ParseOptions) => {
readonly name: string;
readonly age: number;
}
export decodeUnknownSync

@throwsParseError

@since3.10.0

decodeUnknownSync
(
const Person: Schema.Struct<{
name: Schema.refine<string, Schema.Schema<string, string, never>>;
age: Schema.filter<Schema.Schema<number, number, never>>;
}>
Person
)({
name: null
name
: null,
age: number
age
: 18 })
/*
throws:
ParseError: Person
└─ ["name"]
└─ Name
└─ From side refinement failure
└─ Expected string, actual null
*/
// Predicate refinement failure
import Schema
Schema
.
decodeUnknownSync<{
readonly name: string;
readonly age: number;
}, {
readonly name: string;
readonly age: number;
}>(schema: Schema.Schema<{
readonly name: string;
readonly age: number;
}, {
readonly name: string;
readonly age: number;
}, never>, options?: ParseOptions): (u: unknown, overrideOptions?: ParseOptions) => {
readonly name: string;
readonly age: number;
}
export decodeUnknownSync

@throwsParseError

@since3.10.0

decodeUnknownSync
(
const Person: Schema.Struct<{
name: Schema.refine<string, Schema.Schema<string, string, never>>;
age: Schema.filter<Schema.Schema<number, number, never>>;
}>
Person
)({
name: string
name
: "",
age: number
age
: 18 })
/*
throws:
ParseError: Person
└─ ["name"]
└─ Name
└─ Predicate refinement failure
└─ Expected Name, actual ""
*/

In the first example, the error message indicates a “from side” refinement failure in the name property, specifying that a string was expected but received null. In the second example, a “predicate” refinement failure is reported, indicating that a non-empty string was expected for name but an empty string was provided.

Transformations between different types or formats can occasionally result in errors. The system provides a structured error message to specify where the error occurred:

  • Encoded Side Failure: Errors on this side typically indicate that the input to the transformation does not match the expected initial type or format. For example, receiving a null when a string is expected.
  • Transformation Process Failure: This type of error arises when the transformation logic itself fails, such as when the input does not meet the criteria specified within the transformation functions.
  • Type Side Failure: Occurs when the output of a transformation does not meet the schema requirements on the decoded side. This can happen if the transformed value fails subsequent validations or conditions.

Example (Transformation Errors)

import {
import ParseResult
ParseResult
,
import Schema
Schema
} from "effect"
const
const schema: Schema.transformOrFail<typeof Schema.String, Schema.filter<Schema.Schema<string, string, never>>, never>
schema
=
import Schema
Schema
.
const transformOrFail: <Schema.filter<Schema.Schema<string, string, never>>, typeof Schema.String, never, never>(from: typeof Schema.String, to: Schema.filter<Schema.Schema<string, string, never>>, options: {
...;
} | {
...;
}) => Schema.transformOrFail<...> (+1 overload)

Create a new Schema by transforming the input and output of an existing Schema using the provided decoding functions.

@since3.10.0

transformOrFail
(
import Schema
Schema
.
class String
export String

@since3.10.0

String
,
import Schema
Schema
.
class String
export String

@since3.10.0

String
.
Pipeable.pipe<typeof Schema.String, Schema.filter<Schema.Schema<string, string, never>>>(this: typeof Schema.String, ab: (_: typeof Schema.String) => Schema.filter<Schema.Schema<string, string, never>>): Schema.filter<...> (+21 overloads)
pipe
(
import Schema
Schema
.
const minLength: <string>(minLength: number, annotations?: Schema.Annotations.Filter<string, string> | undefined) => <I, R>(self: Schema.Schema<string, I, R>) => Schema.filter<...>

@since3.10.0

minLength
(2)),
{
strict?: true
strict
: true,
decode: (fromA: string, options: ParseOptions, ast: Transformation, fromI: string) => Effect<string, ParseResult.ParseIssue, never>
decode
: (
s: string
s
,
_: ParseOptions
_
,
ast: Transformation
ast
) =>
s: string
s
.
String.length: number

Returns the length of a String object.

length
> 0
?
import ParseResult
ParseResult
.
const succeed: <string>(a: string) => Either<string, ParseResult.ParseIssue>

@since3.10.0

succeed
(
s: string
s
)
:
import ParseResult
ParseResult
.
const fail: (issue: ParseResult.ParseIssue) => Either<never, ParseResult.ParseIssue>

@since3.10.0

fail
(new
import ParseResult
ParseResult
.
constructor Type(ast: AST, actual: unknown, message?: string | undefined): ParseResult.Type

The Type variant of the ParseIssue type represents an error that occurs when the actual value is not of the expected type. The ast field specifies the expected type, and the actual field contains the value that caused the error.

@since3.10.0

Type
(
ast: Transformation
ast
,
s: string
s
)),
encode: (toI: string, options: ParseOptions, ast: Transformation, toA: string) => Effect<string, ParseResult.ParseIssue, never>
encode
:
import ParseResult
ParseResult
.
const succeed: <A>(a: A) => Either<A, ParseResult.ParseIssue>

@since3.10.0

succeed
}
)
// Encoded side failure
import Schema
Schema
.
decodeUnknownSync<string, string>(schema: Schema.Schema<string, string, never>, options?: ParseOptions): (u: unknown, overrideOptions?: ParseOptions) => string
export decodeUnknownSync

@throwsParseError

@since3.10.0

decodeUnknownSync
(
const schema: Schema.transformOrFail<typeof Schema.String, Schema.filter<Schema.Schema<string, string, never>>, never>
schema
)(null)
/*
throws:
ParseError: (string <-> a string at least 2 character(s) long)
└─ Encoded side transformation failure
└─ Expected string, actual null
*/
// transformation failure
import Schema
Schema
.
decodeUnknownSync<string, string>(schema: Schema.Schema<string, string, never>, options?: ParseOptions): (u: unknown, overrideOptions?: ParseOptions) => string
export decodeUnknownSync

@throwsParseError

@since3.10.0

decodeUnknownSync
(
const schema: Schema.transformOrFail<typeof Schema.String, Schema.filter<Schema.Schema<string, string, never>>, never>
schema
)("")
/*
throws:
ParseError: (string <-> a string at least 2 character(s) long)
└─ Transformation process failure
└─ Expected (string <-> a string at least 2 character(s) long), actual ""
*/
// Type side failure
import Schema
Schema
.
decodeUnknownSync<string, string>(schema: Schema.Schema<string, string, never>, options?: ParseOptions): (u: unknown, overrideOptions?: ParseOptions) => string
export decodeUnknownSync

@throwsParseError

@since3.10.0

decodeUnknownSync
(
const schema: Schema.transformOrFail<typeof Schema.String, Schema.filter<Schema.Schema<string, string, never>>, never>
schema
)("a")
/*
throws:
ParseError: (string <-> a string at least 2 character(s) long)
└─ Type side transformation failure
└─ a string at least 2 character(s) long
└─ Predicate refinement failure
└─ Expected a string at least 2 character(s) long, actual "a"
*/

You have the capability to define custom error messages specifically tailored for different parts of your schema using the message annotation. This allows developers to provide more context-specific feedback which can improve the debugging and validation processes.

Here’s an overview of the MessageAnnotation type, which you can use to craft these messages:

type MessageAnnotation = (issue: ParseIssue) =>
| string
| Effect<string>
| {
readonly message: string | Effect<string>
readonly override: boolean
}
Return TypeDescription
stringProvides a static message that directly describes the error.
Effect<string>Utilizes dynamic messages that can incorporate results from synchronous processes or rely on optional dependencies.
Object (with message and override)Allows you to define a specific error message along with a boolean flag (override). This flag determines if the custom message should supersede any default or nested custom messages, providing precise control over the error output displayed to users.

Example (Custom Error Message for a String Schema)

import {
import Schema
Schema
} from "effect"
const
const MyString: Schema.SchemaClass<string, string, never>
MyString
=
import Schema
Schema
.
class String
export String

@since3.10.0

String
.
Annotable<SchemaClass<string, string, never>, string, string, never>.annotations(annotations: Schema.Annotations.GenericSchema<string>): Schema.SchemaClass<string, string, never>

Merges a set of new annotations with existing ones, potentially overwriting any duplicates.

annotations
({
Annotations.Schema<string, readonly []>.message?: MessageAnnotation
message
: () => "not a string"
})
import Schema
Schema
.
decodeUnknownSync<string, string>(schema: Schema.Schema<string, string, never>, options?: ParseOptions): (u: unknown, overrideOptions?: ParseOptions) => string
export decodeUnknownSync

@throwsParseError

@since3.10.0

decodeUnknownSync
(
const MyString: Schema.SchemaClass<string, string, never>
MyString
)(null)
/*
throws:
ParseError: not a string
*/

The general logic followed to determine the messages is as follows:

  1. If no custom messages are set, the default message related to the innermost schema where the operation (i.e., decoding or encoding) failed is used.

  2. If custom messages are set, then the message corresponding to the first failed schema is used, starting from the innermost schema to the outermost. However, if the failing schema does not have a custom message, then the default message is used.

  3. As an opt-in feature, you can override guideline 2 by setting the overwrite flag to true. This allows the custom message to take precedence over all other custom messages from inner schemas. This is to address the scenario where a user wants to define a single cumulative custom message describing the properties that a valid value must have and does not want to see default messages.

Let’s see some practical examples.

Example (Simple Custom Message for Scalar Schema)

import {
import Schema
Schema
} from "effect"
const
const MyString: Schema.SchemaClass<string, string, never>
MyString
=
import Schema
Schema
.
class String
export String

@since3.10.0

String
.
Annotable<SchemaClass<string, string, never>, string, string, never>.annotations(annotations: Schema.Annotations.GenericSchema<string>): Schema.SchemaClass<string, string, never>

Merges a set of new annotations with existing ones, potentially overwriting any duplicates.

annotations
({
Annotations.Schema<string, readonly []>.message?: MessageAnnotation
message
: () => "my custom message"
})
const
const decode: (u: unknown, overrideOptions?: ParseOptions) => string
decode
=
import Schema
Schema
.
decodeUnknownSync<string, string>(schema: Schema.Schema<string, string, never>, options?: ParseOptions): (u: unknown, overrideOptions?: ParseOptions) => string
export decodeUnknownSync

@throwsParseError

@since3.10.0

decodeUnknownSync
(
const MyString: Schema.SchemaClass<string, string, never>
MyString
)
try {
const decode: (u: unknown, overrideOptions?: ParseOptions) => string
decode
(null)
} catch (
var e: any
e
: any) {
var console: Console

The console module provides a simple debugging console that is similar to the JavaScript console mechanism provided by web browsers.

The module exports two specific components:

  • A Console class with methods such as console.log(), console.error() and console.warn() that can be used to write to any Node.js stream.
  • A global console instance configured to write to process.stdout and process.stderr. The global console can be used without importing the node:console module.

Warning: The global console object's methods are neither consistently synchronous like the browser APIs they resemble, nor are they consistently asynchronous like all other Node.js streams. See the note on process I/O for more information.

Example using the global console:

console.log('hello world');
// Prints: hello world, to stdout
console.log('hello %s', 'world');
// Prints: hello world, to stdout
console.error(new Error('Whoops, something bad happened'));
// Prints error message and stack trace to stderr:
// Error: Whoops, something bad happened
// at [eval]:5:15
// at Script.runInThisContext (node:vm:132:18)
// at Object.runInThisContext (node:vm:309:38)
// at node:internal/process/execution:77:19
// at [eval]-wrapper:6:22
// at evalScript (node:internal/process/execution:76:60)
// at node:internal/main/eval_string:23:3
const name = 'Will Robinson';
console.warn(`Danger ${name}! Danger!`);
// Prints: Danger Will Robinson! Danger!, to stderr

Example using the Console class:

const out = getStreamSomehow();
const err = getStreamSomehow();
const myConsole = new console.Console(out, err);
myConsole.log('hello world');
// Prints: hello world, to out
myConsole.log('hello %s', 'world');
// Prints: hello world, to out
myConsole.error(new Error('Whoops, something bad happened'));
// Prints: [Error: Whoops, something bad happened], to err
const name = 'Will Robinson';
myConsole.warn(`Danger ${name}! Danger!`);
// Prints: Danger Will Robinson! Danger!, to err

@seesource

console
.
Console.log(message?: any, ...optionalParams: any[]): void

Prints to stdout with newline. Multiple arguments can be passed, with the first used as the primary message and all additional used as substitution values similar to printf(3) (the arguments are all passed to util.format()).

const count = 5;
console.log('count: %d', count);
// Prints: count: 5, to stdout
console.log('count:', count);
// Prints: count: 5, to stdout

See util.format() for more information.

@sincev0.1.100

log
(
var e: any
e
.
any
message
) // "my custom message"
}

This example demonstrates setting a custom message on the last refinement in a chain of refinements. As you can see, the custom message is only used if the refinement related to maxLength fails; otherwise, default messages are used.

Example (Custom Message on Last Refinement in Chain)

import {
import Schema
Schema
} from "effect"
const
const MyString: Schema.refine<string, Schema.Schema<string, string, never>>
MyString
=
import Schema
Schema
.
class String
export String

@since3.10.0

String
.
Pipeable.pipe<typeof Schema.String, Schema.filter<Schema.Schema<string, string, never>>, Schema.filter<Schema.Schema<string, string, never>>>(this: typeof Schema.String, ab: (_: typeof Schema.String) => Schema.filter<...>, bc: (_: Schema.filter<...>) => Schema.filter<...>): Schema.filter<...> (+21 overloads)
pipe
(
import Schema
Schema
.
const minLength: <string>(minLength: number, annotations?: Schema.Annotations.Filter<string, string> | undefined) => <I, R>(self: Schema.Schema<string, I, R>) => Schema.filter<...>

@since3.10.0

minLength
(1),
import Schema
Schema
.
const maxLength: <string>(maxLength: number, annotations?: Schema.Annotations.Filter<string, string> | undefined) => <I, R>(self: Schema.Schema<string, I, R>) => Schema.filter<...>

@since3.10.0

maxLength
(2)
).
Annotable<refine<string, Schema<string, string, never>>, string, string, never>.annotations(annotations: Schema.Annotations.GenericSchema<string>): Schema.refine<string, Schema.Schema<string, string, never>>

Merges a set of new annotations with existing ones, potentially overwriting any duplicates.

annotations
({
// This message is displayed only if the last filter (`maxLength`) fails
Annotations.Schema<string, readonly []>.message?: MessageAnnotation
message
: () => "my custom message"
})
const
const decode: (u: unknown, overrideOptions?: ParseOptions) => string
decode
=
import Schema
Schema
.
decodeUnknownSync<string, string>(schema: Schema.Schema<string, string, never>, options?: ParseOptions): (u: unknown, overrideOptions?: ParseOptions) => string
export decodeUnknownSync

@throwsParseError

@since3.10.0

decodeUnknownSync
(
const MyString: Schema.refine<string, Schema.Schema<string, string, never>>
MyString
)
try {
const decode: (u: unknown, overrideOptions?: ParseOptions) => string
decode
(null)
} catch (
var e: any
e
: any) {
var console: Console

The console module provides a simple debugging console that is similar to the JavaScript console mechanism provided by web browsers.

The module exports two specific components:

  • A Console class with methods such as console.log(), console.error() and console.warn() that can be used to write to any Node.js stream.
  • A global console instance configured to write to process.stdout and process.stderr. The global console can be used without importing the node:console module.

Warning: The global console object's methods are neither consistently synchronous like the browser APIs they resemble, nor are they consistently asynchronous like all other Node.js streams. See the note on process I/O for more information.

Example using the global console:

console.log('hello world');
// Prints: hello world, to stdout
console.log('hello %s', 'world');
// Prints: hello world, to stdout
console.error(new Error('Whoops, something bad happened'));
// Prints error message and stack trace to stderr:
// Error: Whoops, something bad happened
// at [eval]:5:15
// at Script.runInThisContext (node:vm:132:18)
// at Object.runInThisContext (node:vm:309:38)
// at node:internal/process/execution:77:19
// at [eval]-wrapper:6:22
// at evalScript (node:internal/process/execution:76:60)
// at node:internal/main/eval_string:23:3
const name = 'Will Robinson';
console.warn(`Danger ${name}! Danger!`);
// Prints: Danger Will Robinson! Danger!, to stderr

Example using the Console class:

const out = getStreamSomehow();
const err = getStreamSomehow();
const myConsole = new console.Console(out, err);
myConsole.log('hello world');
// Prints: hello world, to out
myConsole.log('hello %s', 'world');
// Prints: hello world, to out
myConsole.error(new Error('Whoops, something bad happened'));
// Prints: [Error: Whoops, something bad happened], to err
const name = 'Will Robinson';
myConsole.warn(`Danger ${name}! Danger!`);
// Prints: Danger Will Robinson! Danger!, to err

@seesource

console
.
Console.log(message?: any, ...optionalParams: any[]): void

Prints to stdout with newline. Multiple arguments can be passed, with the first used as the primary message and all additional used as substitution values similar to printf(3) (the arguments are all passed to util.format()).

const count = 5;
console.log('count: %d', count);
// Prints: count: 5, to stdout
console.log('count:', count);
// Prints: count: 5, to stdout

See util.format() for more information.

@sincev0.1.100

log
(
var e: any
e
.
any
message
)
/*
a string at most 2 character(s) long
└─ From side refinement failure
└─ a string at least 1 character(s) long
└─ From side refinement failure
└─ Expected string, actual null
*/
}
try {
const decode: (u: unknown, overrideOptions?: ParseOptions) => string
decode
("")
} catch (
var e: any
e
: any) {
var console: Console

The console module provides a simple debugging console that is similar to the JavaScript console mechanism provided by web browsers.

The module exports two specific components:

  • A Console class with methods such as console.log(), console.error() and console.warn() that can be used to write to any Node.js stream.
  • A global console instance configured to write to process.stdout and process.stderr. The global console can be used without importing the node:console module.

Warning: The global console object's methods are neither consistently synchronous like the browser APIs they resemble, nor are they consistently asynchronous like all other Node.js streams. See the note on process I/O for more information.

Example using the global console:

console.log('hello world');
// Prints: hello world, to stdout
console.log('hello %s', 'world');
// Prints: hello world, to stdout
console.error(new Error('Whoops, something bad happened'));
// Prints error message and stack trace to stderr:
// Error: Whoops, something bad happened
// at [eval]:5:15
// at Script.runInThisContext (node:vm:132:18)
// at Object.runInThisContext (node:vm:309:38)
// at node:internal/process/execution:77:19
// at [eval]-wrapper:6:22
// at evalScript (node:internal/process/execution:76:60)
// at node:internal/main/eval_string:23:3
const name = 'Will Robinson';
console.warn(`Danger ${name}! Danger!`);
// Prints: Danger Will Robinson! Danger!, to stderr

Example using the Console class:

const out = getStreamSomehow();
const err = getStreamSomehow();
const myConsole = new console.Console(out, err);
myConsole.log('hello world');
// Prints: hello world, to out
myConsole.log('hello %s', 'world');
// Prints: hello world, to out
myConsole.error(new Error('Whoops, something bad happened'));
// Prints: [Error: Whoops, something bad happened], to err
const name = 'Will Robinson';
myConsole.warn(`Danger ${name}! Danger!`);
// Prints: Danger Will Robinson! Danger!, to err

@seesource

console
.
Console.log(message?: any, ...optionalParams: any[]): void

Prints to stdout with newline. Multiple arguments can be passed, with the first used as the primary message and all additional used as substitution values similar to printf(3) (the arguments are all passed to util.format()).

const count = 5;
console.log('count: %d', count);
// Prints: count: 5, to stdout
console.log('count:', count);
// Prints: count: 5, to stdout

See util.format() for more information.

@sincev0.1.100

log
(
var e: any
e
.
any
message
)
/*
a string at most 2 character(s) long
└─ From side refinement failure
└─ a string at least 1 character(s) long
└─ Predicate refinement failure
└─ Expected a string at least 1 character(s) long, actual ""
*/
}
try {
const decode: (u: unknown, overrideOptions?: ParseOptions) => string
decode
("abc")
} catch (
var e: any
e
: any) {
var console: Console

The console module provides a simple debugging console that is similar to the JavaScript console mechanism provided by web browsers.

The module exports two specific components:

  • A Console class with methods such as console.log(), console.error() and console.warn() that can be used to write to any Node.js stream.
  • A global console instance configured to write to process.stdout and process.stderr. The global console can be used without importing the node:console module.

Warning: The global console object's methods are neither consistently synchronous like the browser APIs they resemble, nor are they consistently asynchronous like all other Node.js streams. See the note on process I/O for more information.

Example using the global console:

console.log('hello world');
// Prints: hello world, to stdout
console.log('hello %s', 'world');
// Prints: hello world, to stdout
console.error(new Error('Whoops, something bad happened'));
// Prints error message and stack trace to stderr:
// Error: Whoops, something bad happened
// at [eval]:5:15
// at Script.runInThisContext (node:vm:132:18)
// at Object.runInThisContext (node:vm:309:38)
// at node:internal/process/execution:77:19
// at [eval]-wrapper:6:22
// at evalScript (node:internal/process/execution:76:60)
// at node:internal/main/eval_string:23:3
const name = 'Will Robinson';
console.warn(`Danger ${name}! Danger!`);
// Prints: Danger Will Robinson! Danger!, to stderr

Example using the Console class:

const out = getStreamSomehow();
const err = getStreamSomehow();
const myConsole = new console.Console(out, err);
myConsole.log('hello world');
// Prints: hello world, to out
myConsole.log('hello %s', 'world');
// Prints: hello world, to out
myConsole.error(new Error('Whoops, something bad happened'));
// Prints: [Error: Whoops, something bad happened], to err
const name = 'Will Robinson';
myConsole.warn(`Danger ${name}! Danger!`);
// Prints: Danger Will Robinson! Danger!, to err

@seesource

console
.
Console.log(message?: any, ...optionalParams: any[]): void

Prints to stdout with newline. Multiple arguments can be passed, with the first used as the primary message and all additional used as substitution values similar to printf(3) (the arguments are all passed to util.format()).

const count = 5;
console.log('count: %d', count);
// Prints: count: 5, to stdout
console.log('count:', count);
// Prints: count: 5, to stdout

See util.format() for more information.

@sincev0.1.100

log
(
var e: any
e
.
any
message
)
// "my custom message"
}

When setting multiple custom messages, the one corresponding to the first failed predicate is used, starting from the innermost refinement to the outermost:

Example (Custom Messages for Multiple Refinements)

import {
import Schema
Schema
} from "effect"
const
const MyString: Schema.filter<Schema.Schema<string, string, never>>
MyString
=
import Schema
Schema
.
class String
export String

@since3.10.0

String
// This message is displayed only if a non-String is passed as input
.
Annotable<SchemaClass<string, string, never>, string, string, never>.annotations(annotations: Schema.Annotations.GenericSchema<string>): Schema.SchemaClass<string, string, never>

Merges a set of new annotations with existing ones, potentially overwriting any duplicates.

annotations
({
Annotations.Schema<string, readonly []>.message?: MessageAnnotation
message
: () => "String custom message" })
.
Pipeable.pipe<Schema.SchemaClass<string, string, never>, Schema.filter<Schema.Schema<string, string, never>>, Schema.filter<Schema.Schema<string, string, never>>>(this: Schema.SchemaClass<...>, ab: (_: Schema.SchemaClass<...>) => Schema.filter<...>, bc: (_: Schema.filter<...>) => Schema.filter<...>): Schema.filter<...> (+21 overloads)
pipe
(
// This message is displayed only if the filter `minLength` fails
import Schema
Schema
.
const minLength: <string>(minLength: number, annotations?: Schema.Annotations.Filter<string, string> | undefined) => <I, R>(self: Schema.Schema<string, I, R>) => Schema.filter<...>

@since3.10.0

minLength
(1, {
Annotations.Schema<A, TypeParameters extends ReadonlyArray<any> = readonly []>.message?: MessageAnnotation
message
: () => "minLength custom message" }),
// This message is displayed only if the filter `maxLength` fails
import Schema
Schema
.
const maxLength: <string>(maxLength: number, annotations?: Schema.Annotations.Filter<string, string> | undefined) => <I, R>(self: Schema.Schema<string, I, R>) => Schema.filter<...>

@since3.10.0

maxLength
(2, {
Annotations.Schema<A, TypeParameters extends ReadonlyArray<any> = readonly []>.message?: MessageAnnotation
message
: () => "maxLength custom message" })
)
const
const decode: (u: unknown, overrideOptions?: ParseOptions) => string
decode
=
import Schema
Schema
.
decodeUnknownSync<string, string>(schema: Schema.Schema<string, string, never>, options?: ParseOptions): (u: unknown, overrideOptions?: ParseOptions) => string
export decodeUnknownSync

@throwsParseError

@since3.10.0

decodeUnknownSync
(
const MyString: Schema.filter<Schema.Schema<string, string, never>>
MyString
)
try {
const decode: (u: unknown, overrideOptions?: ParseOptions) => string
decode
(null)
} catch (
var e: any
e
: any) {
var console: Console

The console module provides a simple debugging console that is similar to the JavaScript console mechanism provided by web browsers.

The module exports two specific components:

  • A Console class with methods such as console.log(), console.error() and console.warn() that can be used to write to any Node.js stream.
  • A global console instance configured to write to process.stdout and process.stderr. The global console can be used without importing the node:console module.

Warning: The global console object's methods are neither consistently synchronous like the browser APIs they resemble, nor are they consistently asynchronous like all other Node.js streams. See the note on process I/O for more information.

Example using the global console:

console.log('hello world');
// Prints: hello world, to stdout
console.log('hello %s', 'world');
// Prints: hello world, to stdout
console.error(new Error('Whoops, something bad happened'));
// Prints error message and stack trace to stderr:
// Error: Whoops, something bad happened
// at [eval]:5:15
// at Script.runInThisContext (node:vm:132:18)
// at Object.runInThisContext (node:vm:309:38)
// at node:internal/process/execution:77:19
// at [eval]-wrapper:6:22
// at evalScript (node:internal/process/execution:76:60)
// at node:internal/main/eval_string:23:3
const name = 'Will Robinson';
console.warn(`Danger ${name}! Danger!`);
// Prints: Danger Will Robinson! Danger!, to stderr

Example using the Console class:

const out = getStreamSomehow();
const err = getStreamSomehow();
const myConsole = new console.Console(out, err);
myConsole.log('hello world');
// Prints: hello world, to out
myConsole.log('hello %s', 'world');
// Prints: hello world, to out
myConsole.error(new Error('Whoops, something bad happened'));
// Prints: [Error: Whoops, something bad happened], to err
const name = 'Will Robinson';
myConsole.warn(`Danger ${name}! Danger!`);
// Prints: Danger Will Robinson! Danger!, to err

@seesource

console
.
Console.log(message?: any, ...optionalParams: any[]): void

Prints to stdout with newline. Multiple arguments can be passed, with the first used as the primary message and all additional used as substitution values similar to printf(3) (the arguments are all passed to util.format()).

const count = 5;
console.log('count: %d', count);
// Prints: count: 5, to stdout
console.log('count:', count);
// Prints: count: 5, to stdout

See util.format() for more information.

@sincev0.1.100

log
(
var e: any
e
.
any
message
) // String custom message
}
try {
const decode: (u: unknown, overrideOptions?: ParseOptions) => string
decode
("")
} catch (
var e: any
e
: any) {
var console: Console

The console module provides a simple debugging console that is similar to the JavaScript console mechanism provided by web browsers.

The module exports two specific components:

  • A Console class with methods such as console.log(), console.error() and console.warn() that can be used to write to any Node.js stream.
  • A global console instance configured to write to process.stdout and process.stderr. The global console can be used without importing the node:console module.

Warning: The global console object's methods are neither consistently synchronous like the browser APIs they resemble, nor are they consistently asynchronous like all other Node.js streams. See the note on process I/O for more information.

Example using the global console:

console.log('hello world');
// Prints: hello world, to stdout
console.log('hello %s', 'world');
// Prints: hello world, to stdout
console.error(new Error('Whoops, something bad happened'));
// Prints error message and stack trace to stderr:
// Error: Whoops, something bad happened
// at [eval]:5:15
// at Script.runInThisContext (node:vm:132:18)
// at Object.runInThisContext (node:vm:309:38)
// at node:internal/process/execution:77:19
// at [eval]-wrapper:6:22
// at evalScript (node:internal/process/execution:76:60)
// at node:internal/main/eval_string:23:3
const name = 'Will Robinson';
console.warn(`Danger ${name}! Danger!`);
// Prints: Danger Will Robinson! Danger!, to stderr

Example using the Console class:

const out = getStreamSomehow();
const err = getStreamSomehow();
const myConsole = new console.Console(out, err);
myConsole.log('hello world');
// Prints: hello world, to out
myConsole.log('hello %s', 'world');
// Prints: hello world, to out
myConsole.error(new Error('Whoops, something bad happened'));
// Prints: [Error: Whoops, something bad happened], to err
const name = 'Will Robinson';
myConsole.warn(`Danger ${name}! Danger!`);
// Prints: Danger Will Robinson! Danger!, to err

@seesource

console
.
Console.log(message?: any, ...optionalParams: any[]): void

Prints to stdout with newline. Multiple arguments can be passed, with the first used as the primary message and all additional used as substitution values similar to printf(3) (the arguments are all passed to util.format()).

const count = 5;
console.log('count: %d', count);
// Prints: count: 5, to stdout
console.log('count:', count);
// Prints: count: 5, to stdout

See util.format() for more information.

@sincev0.1.100

log
(
var e: any
e
.
any
message
) // minLength custom message
}
try {
const decode: (u: unknown, overrideOptions?: ParseOptions) => string
decode
("abc")
} catch (
var e: any
e
: any) {
var console: Console

The console module provides a simple debugging console that is similar to the JavaScript console mechanism provided by web browsers.

The module exports two specific components:

  • A Console class with methods such as console.log(), console.error() and console.warn() that can be used to write to any Node.js stream.
  • A global console instance configured to write to process.stdout and process.stderr. The global console can be used without importing the node:console module.

Warning: The global console object's methods are neither consistently synchronous like the browser APIs they resemble, nor are they consistently asynchronous like all other Node.js streams. See the note on process I/O for more information.

Example using the global console:

console.log('hello world');
// Prints: hello world, to stdout
console.log('hello %s', 'world');
// Prints: hello world, to stdout
console.error(new Error('Whoops, something bad happened'));
// Prints error message and stack trace to stderr:
// Error: Whoops, something bad happened
// at [eval]:5:15
// at Script.runInThisContext (node:vm:132:18)
// at Object.runInThisContext (node:vm:309:38)
// at node:internal/process/execution:77:19
// at [eval]-wrapper:6:22
// at evalScript (node:internal/process/execution:76:60)
// at node:internal/main/eval_string:23:3
const name = 'Will Robinson';
console.warn(`Danger ${name}! Danger!`);
// Prints: Danger Will Robinson! Danger!, to stderr

Example using the Console class:

const out = getStreamSomehow();
const err = getStreamSomehow();
const myConsole = new console.Console(out, err);
myConsole.log('hello world');
// Prints: hello world, to out
myConsole.log('hello %s', 'world');
// Prints: hello world, to out
myConsole.error(new Error('Whoops, something bad happened'));
// Prints: [Error: Whoops, something bad happened], to err
const name = 'Will Robinson';
myConsole.warn(`Danger ${name}! Danger!`);
// Prints: Danger Will Robinson! Danger!, to err

@seesource

console
.
Console.log(message?: any, ...optionalParams: any[]): void

Prints to stdout with newline. Multiple arguments can be passed, with the first used as the primary message and all additional used as substitution values similar to printf(3) (the arguments are all passed to util.format()).

const count = 5;
console.log('count: %d', count);
// Prints: count: 5, to stdout
console.log('count:', count);
// Prints: count: 5, to stdout

See util.format() for more information.

@sincev0.1.100

log
(
var e: any
e
.
any
message
) // maxLength custom message
}

You have the option to change the default behavior by setting the override flag to true. This is useful when you want to create a single comprehensive custom message that describes the required properties of a valid value without displaying default messages.

Example (Overriding Default Messages)

import {
import Schema
Schema
} from "effect"
const
const MyString: Schema.refine<string, Schema.Schema<string, string, never>>
MyString
=
import Schema
Schema
.
class String
export String

@since3.10.0

String
.
Pipeable.pipe<typeof Schema.String, Schema.filter<Schema.Schema<string, string, never>>, Schema.filter<Schema.Schema<string, string, never>>>(this: typeof Schema.String, ab: (_: typeof Schema.String) => Schema.filter<...>, bc: (_: Schema.filter<...>) => Schema.filter<...>): Schema.filter<...> (+21 overloads)
pipe
(
import Schema
Schema
.
const minLength: <string>(minLength: number, annotations?: Schema.Annotations.Filter<string, string> | undefined) => <I, R>(self: Schema.Schema<string, I, R>) => Schema.filter<...>

@since3.10.0

minLength
(1),
import Schema
Schema
.
const maxLength: <string>(maxLength: number, annotations?: Schema.Annotations.Filter<string, string> | undefined) => <I, R>(self: Schema.Schema<string, I, R>) => Schema.filter<...>

@since3.10.0

maxLength
(2)
).
Annotable<refine<string, Schema<string, string, never>>, string, string, never>.annotations(annotations: Schema.Annotations.GenericSchema<string>): Schema.refine<string, Schema.Schema<string, string, never>>

Merges a set of new annotations with existing ones, potentially overwriting any duplicates.

annotations
({
// By setting the `override` flag to `true`, this message will always be shown for any error
Annotations.Schema<string, readonly []>.message?: MessageAnnotation
message
: () => ({
message: string | Effect<string, never, never>
message
: "my custom message",
override: boolean
override
: true })
})
const
const decode: (u: unknown, overrideOptions?: ParseOptions) => string
decode
=
import Schema
Schema
.
decodeUnknownSync<string, string>(schema: Schema.Schema<string, string, never>, options?: ParseOptions): (u: unknown, overrideOptions?: ParseOptions) => string
export decodeUnknownSync

@throwsParseError

@since3.10.0

decodeUnknownSync
(
const MyString: Schema.refine<string, Schema.Schema<string, string, never>>
MyString
)
try {
const decode: (u: unknown, overrideOptions?: ParseOptions) => string
decode
(null)
} catch (
var e: any
e
: any) {
var console: Console

The console module provides a simple debugging console that is similar to the JavaScript console mechanism provided by web browsers.

The module exports two specific components:

  • A Console class with methods such as console.log(), console.error() and console.warn() that can be used to write to any Node.js stream.
  • A global console instance configured to write to process.stdout and process.stderr. The global console can be used without importing the node:console module.

Warning: The global console object's methods are neither consistently synchronous like the browser APIs they resemble, nor are they consistently asynchronous like all other Node.js streams. See the note on process I/O for more information.

Example using the global console:

console.log('hello world');
// Prints: hello world, to stdout
console.log('hello %s', 'world');
// Prints: hello world, to stdout
console.error(new Error('Whoops, something bad happened'));
// Prints error message and stack trace to stderr:
// Error: Whoops, something bad happened
// at [eval]:5:15
// at Script.runInThisContext (node:vm:132:18)
// at Object.runInThisContext (node:vm:309:38)
// at node:internal/process/execution:77:19
// at [eval]-wrapper:6:22
// at evalScript (node:internal/process/execution:76:60)
// at node:internal/main/eval_string:23:3
const name = 'Will Robinson';
console.warn(`Danger ${name}! Danger!`);
// Prints: Danger Will Robinson! Danger!, to stderr

Example using the Console class:

const out = getStreamSomehow();
const err = getStreamSomehow();
const myConsole = new console.Console(out, err);
myConsole.log('hello world');
// Prints: hello world, to out
myConsole.log('hello %s', 'world');
// Prints: hello world, to out
myConsole.error(new Error('Whoops, something bad happened'));
// Prints: [Error: Whoops, something bad happened], to err
const name = 'Will Robinson';
myConsole.warn(`Danger ${name}! Danger!`);
// Prints: Danger Will Robinson! Danger!, to err

@seesource

console
.
Console.log(message?: any, ...optionalParams: any[]): void

Prints to stdout with newline. Multiple arguments can be passed, with the first used as the primary message and all additional used as substitution values similar to printf(3) (the arguments are all passed to util.format()).

const count = 5;
console.log('count: %d', count);
// Prints: count: 5, to stdout
console.log('count:', count);
// Prints: count: 5, to stdout

See util.format() for more information.

@sincev0.1.100

log
(
var e: any
e
.
any
message
) // my custom message
}
try {
const decode: (u: unknown, overrideOptions?: ParseOptions) => string
decode
("")
} catch (
var e: any
e
: any) {
var console: Console

The console module provides a simple debugging console that is similar to the JavaScript console mechanism provided by web browsers.

The module exports two specific components:

  • A Console class with methods such as console.log(), console.error() and console.warn() that can be used to write to any Node.js stream.
  • A global console instance configured to write to process.stdout and process.stderr. The global console can be used without importing the node:console module.

Warning: The global console object's methods are neither consistently synchronous like the browser APIs they resemble, nor are they consistently asynchronous like all other Node.js streams. See the note on process I/O for more information.

Example using the global console:

console.log('hello world');
// Prints: hello world, to stdout
console.log('hello %s', 'world');
// Prints: hello world, to stdout
console.error(new Error('Whoops, something bad happened'));
// Prints error message and stack trace to stderr:
// Error: Whoops, something bad happened
// at [eval]:5:15
// at Script.runInThisContext (node:vm:132:18)
// at Object.runInThisContext (node:vm:309:38)
// at node:internal/process/execution:77:19
// at [eval]-wrapper:6:22
// at evalScript (node:internal/process/execution:76:60)
// at node:internal/main/eval_string:23:3
const name = 'Will Robinson';
console.warn(`Danger ${name}! Danger!`);
// Prints: Danger Will Robinson! Danger!, to stderr

Example using the Console class:

const out = getStreamSomehow();
const err = getStreamSomehow();
const myConsole = new console.Console(out, err);
myConsole.log('hello world');
// Prints: hello world, to out
myConsole.log('hello %s', 'world');
// Prints: hello world, to out
myConsole.error(new Error('Whoops, something bad happened'));
// Prints: [Error: Whoops, something bad happened], to err
const name = 'Will Robinson';
myConsole.warn(`Danger ${name}! Danger!`);
// Prints: Danger Will Robinson! Danger!, to err

@seesource

console
.
Console.log(message?: any, ...optionalParams: any[]): void

Prints to stdout with newline. Multiple arguments can be passed, with the first used as the primary message and all additional used as substitution values similar to printf(3) (the arguments are all passed to util.format()).

const count = 5;
console.log('count: %d', count);
// Prints: count: 5, to stdout
console.log('count:', count);
// Prints: count: 5, to stdout

See util.format() for more information.

@sincev0.1.100

log
(
var e: any
e
.
any
message
) // my custom message
}
try {
const decode: (u: unknown, overrideOptions?: ParseOptions) => string
decode
("abc")
} catch (
var e: any
e
: any) {
var console: Console

The console module provides a simple debugging console that is similar to the JavaScript console mechanism provided by web browsers.

The module exports two specific components:

  • A Console class with methods such as console.log(), console.error() and console.warn() that can be used to write to any Node.js stream.
  • A global console instance configured to write to process.stdout and process.stderr. The global console can be used without importing the node:console module.

Warning: The global console object's methods are neither consistently synchronous like the browser APIs they resemble, nor are they consistently asynchronous like all other Node.js streams. See the note on process I/O for more information.

Example using the global console:

console.log('hello world');
// Prints: hello world, to stdout
console.log('hello %s', 'world');
// Prints: hello world, to stdout
console.error(new Error('Whoops, something bad happened'));
// Prints error message and stack trace to stderr:
// Error: Whoops, something bad happened
// at [eval]:5:15
// at Script.runInThisContext (node:vm:132:18)
// at Object.runInThisContext (node:vm:309:38)
// at node:internal/process/execution:77:19
// at [eval]-wrapper:6:22
// at evalScript (node:internal/process/execution:76:60)
// at node:internal/main/eval_string:23:3
const name = 'Will Robinson';
console.warn(`Danger ${name}! Danger!`);
// Prints: Danger Will Robinson! Danger!, to stderr

Example using the Console class:

const out = getStreamSomehow();
const err = getStreamSomehow();
const myConsole = new console.Console(out, err);
myConsole.log('hello world');
// Prints: hello world, to out
myConsole.log('hello %s', 'world');
// Prints: hello world, to out
myConsole.error(new Error('Whoops, something bad happened'));
// Prints: [Error: Whoops, something bad happened], to err
const name = 'Will Robinson';
myConsole.warn(`Danger ${name}! Danger!`);
// Prints: Danger Will Robinson! Danger!, to err

@seesource

console
.
Console.log(message?: any, ...optionalParams: any[]): void

Prints to stdout with newline. Multiple arguments can be passed, with the first used as the primary message and all additional used as substitution values similar to printf(3) (the arguments are all passed to util.format()).

const count = 5;
console.log('count: %d', count);
// Prints: count: 5, to stdout
console.log('count:', count);
// Prints: count: 5, to stdout

See util.format() for more information.

@sincev0.1.100

log
(
var e: any
e
.
any
message
) // my custom message
}

In this example, IntFromString is a transformation schema that converts strings to integers. It applies specific validation messages based on different scenarios.

Example (Custom Error Messages for String-to-Integer Transformation)

import {
import ParseResult
ParseResult
,
import Schema
Schema
} from "effect"
const
const IntFromString: Schema.transformOrFail<Schema.SchemaClass<string, string, never>, Schema.refine<number, Schema.Schema<number, number, never>>, never>
IntFromString
=
import Schema
Schema
.
const transformOrFail: <Schema.refine<number, Schema.Schema<number, number, never>>, Schema.SchemaClass<string, string, never>, never, never>(from: Schema.SchemaClass<string, string, never>, to: Schema.refine<...>, options: {
...;
} | {
...;
}) => Schema.transformOrFail<...> (+1 overload)

Create a new Schema by transforming the input and output of an existing Schema using the provided decoding functions.

@since3.10.0

transformOrFail
(
// This message is displayed only if the input is not a string
import Schema
Schema
.
class String
export String

@since3.10.0

String
.
Annotable<SchemaClass<string, string, never>, string, string, never>.annotations(annotations: Schema.Annotations.GenericSchema<string>): Schema.SchemaClass<string, string, never>

Merges a set of new annotations with existing ones, potentially overwriting any duplicates.

annotations
({
Annotations.Schema<string, readonly []>.message?: MessageAnnotation
message
: () => "please enter a string" }),
// This message is displayed only if the input can be converted
// to a number but it's not an integer
import Schema
Schema
.
class Int

@since3.10.0

Int
.
Annotable<refine<number, Schema<number, number, never>>, number, number, never>.annotations(annotations: Schema.Annotations.GenericSchema<number>): Schema.refine<number, Schema.Schema<number, number, never>>

Merges a set of new annotations with existing ones, potentially overwriting any duplicates.

annotations
({
Annotations.Schema<A, TypeParameters extends ReadonlyArray<any> = readonly []>.message?: MessageAnnotation
message
: () => "please enter an integer" }),
{
strict?: true
strict
: true,
decode: (fromA: string, options: ParseOptions, ast: Transformation, fromI: string) => Effect<number, ParseResult.ParseIssue, never>
decode
: (
s: string
s
,
_: ParseOptions
_
,
ast: Transformation
ast
) => {
const
const n: number
n
=
var Number: NumberConstructor
(value?: any) => number

An object that represents a number of any kind. All JavaScript numbers are 64-bit floating-point numbers.

Number
(
s: string
s
)
return
var Number: NumberConstructor

An object that represents a number of any kind. All JavaScript numbers are 64-bit floating-point numbers.

Number
.
NumberConstructor.isNaN(number: unknown): boolean

Returns a Boolean value that indicates whether a value is the reserved value NaN (not a number). Unlike the global isNaN(), Number.isNaN() doesn't forcefully convert the parameter to a number. Only values of the type number, that are also NaN, result in true.

@paramnumber A numeric value.

isNaN
(
const n: number
n
)
?
import ParseResult
ParseResult
.
const fail: (issue: ParseResult.ParseIssue) => Either<never, ParseResult.ParseIssue>

@since3.10.0

fail
(new
import ParseResult
ParseResult
.
constructor Type(ast: AST, actual: unknown, message?: string | undefined): ParseResult.Type

The Type variant of the ParseIssue type represents an error that occurs when the actual value is not of the expected type. The ast field specifies the expected type, and the actual field contains the value that caused the error.

@since3.10.0

Type
(
ast: Transformation
ast
,
s: string
s
))
:
import ParseResult
ParseResult
.
const succeed: <number>(a: number) => Either<number, ParseResult.ParseIssue>

@since3.10.0

succeed
(
const n: number
n
)
},
encode: (toI: number, options: ParseOptions, ast: Transformation, toA: number) => Effect<string, ParseResult.ParseIssue, never>
encode
: (
n: number
n
) =>
import ParseResult
ParseResult
.
const succeed: <string>(a: string) => Either<string, ParseResult.ParseIssue>

@since3.10.0

succeed
(
var String: StringConstructor
(value?: any) => string

Allows manipulation and formatting of text strings and determination and location of substrings within strings.

String
(
n: number
n
))
}
)
// This message is displayed only if the input
// cannot be converted to a number
.
Annotable<transformOrFail<SchemaClass<string, string, never>, refine<number, Schema<number, number, never>>, never>, number, string, never>.annotations(annotations: Schema.Annotations.GenericSchema<number>): Schema.transformOrFail<Schema.SchemaClass<string, string, never>, Schema.refine<number, Schema.Schema<number, number, never>>, never>

Merges a set of new annotations with existing ones, potentially overwriting any duplicates.

annotations
({
Annotations.Schema<A, TypeParameters extends ReadonlyArray<any> = readonly []>.message?: MessageAnnotation
message
: () => "please enter a parseable string" })
const
const decode: (u: unknown, overrideOptions?: ParseOptions) => number
decode
=
import Schema
Schema
.
decodeUnknownSync<number, string>(schema: Schema.Schema<number, string, never>, options?: ParseOptions): (u: unknown, overrideOptions?: ParseOptions) => number
export decodeUnknownSync

@throwsParseError

@since3.10.0

decodeUnknownSync
(
const IntFromString: Schema.transformOrFail<Schema.SchemaClass<string, string, never>, Schema.refine<number, Schema.Schema<number, number, never>>, never>
IntFromString
)
try {
const decode: (u: unknown, overrideOptions?: ParseOptions) => number
decode
(null)
} catch (
var e: any
e
: any) {
var console: Console

The console module provides a simple debugging console that is similar to the JavaScript console mechanism provided by web browsers.

The module exports two specific components:

  • A Console class with methods such as console.log(), console.error() and console.warn() that can be used to write to any Node.js stream.
  • A global console instance configured to write to process.stdout and process.stderr. The global console can be used without importing the node:console module.

Warning: The global console object's methods are neither consistently synchronous like the browser APIs they resemble, nor are they consistently asynchronous like all other Node.js streams. See the note on process I/O for more information.

Example using the global console:

console.log('hello world');
// Prints: hello world, to stdout
console.log('hello %s', 'world');
// Prints: hello world, to stdout
console.error(new Error('Whoops, something bad happened'));
// Prints error message and stack trace to stderr:
// Error: Whoops, something bad happened
// at [eval]:5:15
// at Script.runInThisContext (node:vm:132:18)
// at Object.runInThisContext (node:vm:309:38)
// at node:internal/process/execution:77:19
// at [eval]-wrapper:6:22
// at evalScript (node:internal/process/execution:76:60)
// at node:internal/main/eval_string:23:3
const name = 'Will Robinson';
console.warn(`Danger ${name}! Danger!`);
// Prints: Danger Will Robinson! Danger!, to stderr

Example using the Console class:

const out = getStreamSomehow();
const err = getStreamSomehow();
const myConsole = new console.Console(out, err);
myConsole.log('hello world');
// Prints: hello world, to out
myConsole.log('hello %s', 'world');
// Prints: hello world, to out
myConsole.error(new Error('Whoops, something bad happened'));
// Prints: [Error: Whoops, something bad happened], to err
const name = 'Will Robinson';
myConsole.warn(`Danger ${name}! Danger!`);
// Prints: Danger Will Robinson! Danger!, to err

@seesource

console
.
Console.log(message?: any, ...optionalParams: any[]): void

Prints to stdout with newline. Multiple arguments can be passed, with the first used as the primary message and all additional used as substitution values similar to printf(3) (the arguments are all passed to util.format()).

const count = 5;
console.log('count: %d', count);
// Prints: count: 5, to stdout
console.log('count:', count);
// Prints: count: 5, to stdout

See util.format() for more information.

@sincev0.1.100

log
(
var e: any
e
.
any
message
) // please enter a string
}
try {
const decode: (u: unknown, overrideOptions?: ParseOptions) => number
decode
("1.2")
} catch (
var e: any
e
: any) {
var console: Console

The console module provides a simple debugging console that is similar to the JavaScript console mechanism provided by web browsers.

The module exports two specific components:

  • A Console class with methods such as console.log(), console.error() and console.warn() that can be used to write to any Node.js stream.
  • A global console instance configured to write to process.stdout and process.stderr. The global console can be used without importing the node:console module.

Warning: The global console object's methods are neither consistently synchronous like the browser APIs they resemble, nor are they consistently asynchronous like all other Node.js streams. See the note on process I/O for more information.

Example using the global console:

console.log('hello world');
// Prints: hello world, to stdout
console.log('hello %s', 'world');
// Prints: hello world, to stdout
console.error(new Error('Whoops, something bad happened'));
// Prints error message and stack trace to stderr:
// Error: Whoops, something bad happened
// at [eval]:5:15
// at Script.runInThisContext (node:vm:132:18)
// at Object.runInThisContext (node:vm:309:38)
// at node:internal/process/execution:77:19
// at [eval]-wrapper:6:22
// at evalScript (node:internal/process/execution:76:60)
// at node:internal/main/eval_string:23:3
const name = 'Will Robinson';
console.warn(`Danger ${name}! Danger!`);
// Prints: Danger Will Robinson! Danger!, to stderr

Example using the Console class:

const out = getStreamSomehow();
const err = getStreamSomehow();
const myConsole = new console.Console(out, err);
myConsole.log('hello world');
// Prints: hello world, to out
myConsole.log('hello %s', 'world');
// Prints: hello world, to out
myConsole.error(new Error('Whoops, something bad happened'));
// Prints: [Error: Whoops, something bad happened], to err
const name = 'Will Robinson';
myConsole.warn(`Danger ${name}! Danger!`);
// Prints: Danger Will Robinson! Danger!, to err

@seesource

console
.
Console.log(message?: any, ...optionalParams: any[]): void

Prints to stdout with newline. Multiple arguments can be passed, with the first used as the primary message and all additional used as substitution values similar to printf(3) (the arguments are all passed to util.format()).

const count = 5;
console.log('count: %d', count);
// Prints: count: 5, to stdout
console.log('count:', count);
// Prints: count: 5, to stdout

See util.format() for more information.

@sincev0.1.100

log
(
var e: any
e
.
any
message
) // please enter an integer
}
try {
const decode: (u: unknown, overrideOptions?: ParseOptions) => number
decode
("not a number")
} catch (
var e: any
e
: any) {
var console: Console

The console module provides a simple debugging console that is similar to the JavaScript console mechanism provided by web browsers.

The module exports two specific components:

  • A Console class with methods such as console.log(), console.error() and console.warn() that can be used to write to any Node.js stream.
  • A global console instance configured to write to process.stdout and process.stderr. The global console can be used without importing the node:console module.

Warning: The global console object's methods are neither consistently synchronous like the browser APIs they resemble, nor are they consistently asynchronous like all other Node.js streams. See the note on process I/O for more information.

Example using the global console:

console.log('hello world');
// Prints: hello world, to stdout
console.log('hello %s', 'world');
// Prints: hello world, to stdout
console.error(new Error('Whoops, something bad happened'));
// Prints error message and stack trace to stderr:
// Error: Whoops, something bad happened
// at [eval]:5:15
// at Script.runInThisContext (node:vm:132:18)
// at Object.runInThisContext (node:vm:309:38)
// at node:internal/process/execution:77:19
// at [eval]-wrapper:6:22
// at evalScript (node:internal/process/execution:76:60)
// at node:internal/main/eval_string:23:3
const name = 'Will Robinson';
console.warn(`Danger ${name}! Danger!`);
// Prints: Danger Will Robinson! Danger!, to stderr

Example using the Console class:

const out = getStreamSomehow();
const err = getStreamSomehow();
const myConsole = new console.Console(out, err);
myConsole.log('hello world');
// Prints: hello world, to out
myConsole.log('hello %s', 'world');
// Prints: hello world, to out
myConsole.error(new Error('Whoops, something bad happened'));
// Prints: [Error: Whoops, something bad happened], to err
const name = 'Will Robinson';
myConsole.warn(`Danger ${name}! Danger!`);
// Prints: Danger Will Robinson! Danger!, to err

@seesource

console
.
Console.log(message?: any, ...optionalParams: any[]): void

Prints to stdout with newline. Multiple arguments can be passed, with the first used as the primary message and all additional used as substitution values similar to printf(3) (the arguments are all passed to util.format()).

const count = 5;
console.log('count: %d', count);
// Prints: count: 5, to stdout
console.log('count:', count);
// Prints: count: 5, to stdout

See util.format() for more information.

@sincev0.1.100

log
(
var e: any
e
.
any
message
) // please enter a parseable string
}

The custom message system becomes especially handy when dealing with complex schemas, unlike simple scalar values like string or number. For instance, consider a schema comprising nested structures, such as a struct containing an array of other structs. Let’s explore an example demonstrating the advantage of default messages in handling decoding errors within such nested structures:

Example (Custom Error Messages in Nested Schemas)

import {
import Schema
Schema
} from "effect"
import {
function pipe<A>(a: A): A (+19 overloads)

Pipes the value of an expression into a pipeline of functions.

When to Use

This is useful in combination with data-last functions as a simulation of methods:

as.map(f).filter(g)

becomes:

import { pipe, Array } from "effect"
pipe(as, Array.map(f), Array.filter(g))

Details

The pipe function is a utility that allows us to compose functions in a readable and sequential manner. It takes the output of one function and passes it as the input to the next function in the pipeline. This enables us to build complex transformations by chaining multiple functions together.

import { pipe } from "effect"
const result = pipe(input, func1, func2, ..., funcN)

In this syntax, input is the initial value, and func1, func2, ..., funcN are the functions to be applied in sequence. The result of each function becomes the input for the next function, and the final result is returned.

Here's an illustration of how pipe works:

┌───────┐ ┌───────┐ ┌───────┐ ┌───────┐ ┌───────┐ ┌────────┐
│ input │───►│ func1 │───►│ func2 │───►│ ... │───►│ funcN │───►│ result │
└───────┘ └───────┘ └───────┘ └───────┘ └───────┘ └────────┘

It's important to note that functions passed to pipe must have a single argument because they are only called with a single argument.

@example

// Example: Chaining Arithmetic Operations
import { pipe } from "effect"
// Define simple arithmetic operations
const increment = (x: number) => x + 1
const double = (x: number) => x * 2
const subtractTen = (x: number) => x - 10
// Sequentially apply these operations using `pipe`
const result = pipe(5, increment, double, subtractTen)
console.log(result)
// Output: 2

@since2.0.0

pipe
} from "effect"
const
const schema: Schema.Struct<{
outcomes: Schema.filter<Schema.Schema<readonly {
readonly id: string;
readonly text: string;
}[], readonly {
readonly id: string;
readonly text: string;
}[], never>>;
}>
schema
=
import Schema
Schema
.
function Struct<{
outcomes: Schema.filter<Schema.Schema<readonly {
readonly id: string;
readonly text: string;
}[], readonly {
readonly id: string;
readonly text: string;
}[], never>>;
}>(fields: {
outcomes: Schema.filter<Schema.Schema<readonly {
readonly id: string;
readonly text: string;
}[], readonly {
readonly id: string;
readonly text: string;
}[], never>>;
}): Schema.Struct<...> (+1 overload)

@since3.10.0

Struct
({
outcomes: Schema.filter<Schema.Schema<readonly {
readonly id: string;
readonly text: string;
}[], readonly {
readonly id: string;
readonly text: string;
}[], never>>
outcomes
:
pipe<Schema.Array$<Schema.Struct<{
id: typeof Schema.String;
text: Schema.filter<Schema.Schema<string, string, never>>;
}>>, Schema.filter<Schema.Schema<readonly {
readonly id: string;
readonly text: string;
}[], readonly {
...;
}[], never>>>(a: Schema.Array$<...>, ab: (a: Schema.Array$<...>) => Schema.filter<...>): Schema.filter<...> (+19 overloads)

Pipes the value of an expression into a pipeline of functions.

When to Use

This is useful in combination with data-last functions as a simulation of methods:

as.map(f).filter(g)

becomes:

import { pipe, Array } from "effect"
pipe(as, Array.map(f), Array.filter(g))

Details

The pipe function is a utility that allows us to compose functions in a readable and sequential manner. It takes the output of one function and passes it as the input to the next function in the pipeline. This enables us to build complex transformations by chaining multiple functions together.

import { pipe } from "effect"
const result = pipe(input, func1, func2, ..., funcN)

In this syntax, input is the initial value, and func1, func2, ..., funcN are the functions to be applied in sequence. The result of each function becomes the input for the next function, and the final result is returned.

Here's an illustration of how pipe works:

┌───────┐ ┌───────┐ ┌───────┐ ┌───────┐ ┌───────┐ ┌────────┐
│ input │───►│ func1 │───►│ func2 │───►│ ... │───►│ funcN │───►│ result │
└───────┘ └───────┘ └───────┘ └───────┘ └───────┘ └────────┘

It's important to note that functions passed to pipe must have a single argument because they are only called with a single argument.

@example

// Example: Chaining Arithmetic Operations
import { pipe } from "effect"
// Define simple arithmetic operations
const increment = (x: number) => x + 1
const double = (x: number) => x * 2
const subtractTen = (x: number) => x - 10
// Sequentially apply these operations using `pipe`
const result = pipe(5, increment, double, subtractTen)
console.log(result)
// Output: 2

@since2.0.0

pipe
(
import Schema
Schema
.
Array<Schema.Struct<{
id: typeof Schema.String;
text: Schema.filter<Schema.Schema<string, string, never>>;
}>>(value: Schema.Struct<{
id: typeof Schema.String;
text: Schema.filter<Schema.Schema<string, string, never>>;
}>): Schema.Array$<...>
export Array

@since3.10.0

Array
(
import Schema
Schema
.
function Struct<{
id: typeof Schema.String;
text: Schema.filter<Schema.Schema<string, string, never>>;
}>(fields: {
id: typeof Schema.String;
text: Schema.filter<Schema.Schema<string, string, never>>;
}): Schema.Struct<...> (+1 overload)

@since3.10.0

Struct
({
id: typeof Schema.String
id
:
import Schema
Schema
.
class String
export String

@since3.10.0

String
,
text: Schema.filter<Schema.Schema<string, string, never>>
text
:
pipe<Schema.SchemaClass<string, string, never>, Schema.filter<Schema.Schema<string, string, never>>, Schema.filter<Schema.Schema<string, string, never>>>(a: Schema.SchemaClass<...>, ab: (a: Schema.SchemaClass<...>) => Schema.filter<...>, bc: (b: Schema.filter<...>) => Schema.filter<...>): Schema.filter<...> (+19 overloads)

Pipes the value of an expression into a pipeline of functions.

When to Use

This is useful in combination with data-last functions as a simulation of methods:

as.map(f).filter(g)

becomes:

import { pipe, Array } from "effect"
pipe(as, Array.map(f), Array.filter(g))

Details

The pipe function is a utility that allows us to compose functions in a readable and sequential manner. It takes the output of one function and passes it as the input to the next function in the pipeline. This enables us to build complex transformations by chaining multiple functions together.

import { pipe } from "effect"
const result = pipe(input, func1, func2, ..., funcN)

In this syntax, input is the initial value, and func1, func2, ..., funcN are the functions to be applied in sequence. The result of each function becomes the input for the next function, and the final result is returned.

Here's an illustration of how pipe works:

┌───────┐ ┌───────┐ ┌───────┐ ┌───────┐ ┌───────┐ ┌────────┐
│ input │───►│ func1 │───►│ func2 │───►│ ... │───►│ funcN │───►│ result │
└───────┘ └───────┘ └───────┘ └───────┘ └───────┘ └────────┘

It's important to note that functions passed to pipe must have a single argument because they are only called with a single argument.

@example

// Example: Chaining Arithmetic Operations
import { pipe } from "effect"
// Define simple arithmetic operations
const increment = (x: number) => x + 1
const double = (x: number) => x * 2
const subtractTen = (x: number) => x - 10
// Sequentially apply these operations using `pipe`
const result = pipe(5, increment, double, subtractTen)
console.log(result)
// Output: 2

@since2.0.0

pipe
(
import Schema
Schema
.
class String
export String

@since3.10.0

String
.
Annotable<SchemaClass<string, string, never>, string, string, never>.annotations(annotations: Schema.Annotations.GenericSchema<string>): Schema.SchemaClass<string, string, never>

Merges a set of new annotations with existing ones, potentially overwriting any duplicates.

annotations
({
Annotations.Schema<A, TypeParameters extends ReadonlyArray<any> = readonly []>.message?: MessageAnnotation
message
: () => "error_invalid_outcome_type"
}),
import Schema
Schema
.
const minLength: <string>(minLength: number, annotations?: Schema.Annotations.Filter<string, string> | undefined) => <I, R>(self: Schema.Schema<string, I, R>) => Schema.filter<...>

@since3.10.0

minLength
(1, {
Annotations.Schema<A, TypeParameters extends ReadonlyArray<any> = readonly []>.message?: MessageAnnotation
message
: () => "error_required_field" }),
import Schema
Schema
.
const maxLength: <string>(maxLength: number, annotations?: Schema.Annotations.Filter<string, string> | undefined) => <I, R>(self: Schema.Schema<string, I, R>) => Schema.filter<...>

@since3.10.0

maxLength
(50, {
Annotations.Schema<A, TypeParameters extends ReadonlyArray<any> = readonly []>.message?: MessageAnnotation
message
: () => "error_max_length_field"
})
)
})
),
import Schema
Schema
.
const minItems: <{
readonly id: string;
readonly text: string;
}>(n: number, annotations?: Schema.Annotations.Filter<readonly {
readonly id: string;
readonly text: string;
}[], readonly {
readonly id: string;
readonly text: string;
}[]> | undefined) => <I, R>(self: Schema.Schema<...>) => Schema.filter<...>

@since3.10.0

minItems
(1, {
Annotations.Schema<A, TypeParameters extends ReadonlyArray<any> = readonly []>.message?: MessageAnnotation
message
: () => "error_min_length_field" })
)
})
import Schema
Schema
.
decodeUnknownSync<{
readonly outcomes: readonly {
readonly id: string;
readonly text: string;
}[];
}, {
readonly outcomes: readonly {
readonly id: string;
readonly text: string;
}[];
}>(schema: Schema.Schema<{
readonly outcomes: readonly {
readonly id: string;
readonly text: string;
}[];
}, {
readonly outcomes: readonly {
readonly id: string;
readonly text: string;
}[];
}, never>, options?: ParseOptions): (u: unknown, overrideOptions?: ParseOptions) => {
readonly outcomes: readonly {
readonly id: string;
readonly text: string;
}[];
}
export decodeUnknownSync

@throwsParseError

@since3.10.0

decodeUnknownSync
(
const schema: Schema.Struct<{
outcomes: Schema.filter<Schema.Schema<readonly {
readonly id: string;
readonly text: string;
}[], readonly {
readonly id: string;
readonly text: string;
}[], never>>;
}>
schema
, {
ParseOptions.errors?: "first" | "all" | undefined

The errors option allows you to receive all parsing errors when attempting to parse a value using a schema. By default only the first error is returned, but by setting the errors option to "all", you can receive all errors that occurred during the parsing process. This can be useful for debugging or for providing more comprehensive error messages to the user.

default: "first"

@since3.10.0

errors
: "all" })({
outcomes: never[]
outcomes
: []
})
/*
throws
ParseError: { readonly outcomes: an array of at least 1 items }
└─ ["outcomes"]
└─ error_min_length_field
*/
import Schema
Schema
.
decodeUnknownSync<{
readonly outcomes: readonly {
readonly id: string;
readonly text: string;
}[];
}, {
readonly outcomes: readonly {
readonly id: string;
readonly text: string;
}[];
}>(schema: Schema.Schema<{
readonly outcomes: readonly {
readonly id: string;
readonly text: string;
}[];
}, {
readonly outcomes: readonly {
readonly id: string;
readonly text: string;
}[];
}, never>, options?: ParseOptions): (u: unknown, overrideOptions?: ParseOptions) => {
readonly outcomes: readonly {
readonly id: string;
readonly text: string;
}[];
}
export decodeUnknownSync

@throwsParseError

@since3.10.0

decodeUnknownSync
(
const schema: Schema.Struct<{
outcomes: Schema.filter<Schema.Schema<readonly {
readonly id: string;
readonly text: string;
}[], readonly {
readonly id: string;
readonly text: string;
}[], never>>;
}>
schema
, {
ParseOptions.errors?: "first" | "all" | undefined

The errors option allows you to receive all parsing errors when attempting to parse a value using a schema. By default only the first error is returned, but by setting the errors option to "all", you can receive all errors that occurred during the parsing process. This can be useful for debugging or for providing more comprehensive error messages to the user.

default: "first"

@since3.10.0

errors
: "all" })({
outcomes: {
id: string;
text: string;
}[]
outcomes
: [
{
id: string
id
: "1",
text: string
text
: "" },
{
id: string
id
: "2",
text: string
text
: "this one is valid" },
{
id: string
id
: "3",
text: string
text
: "1234567890".
String.repeat(count: number): string

Returns a String value that is made from count copies appended together. If count is 0, the empty string is returned.

@paramcount number of copies to append

repeat
(6) }
]
})
/*
throws
ParseError: { readonly outcomes: an array of at least 1 items }
└─ ["outcomes"]
└─ an array of at least 1 items
└─ From side refinement failure
└─ ReadonlyArray<{ readonly id: string; readonly text: a string at most 50 character(s) long }>
├─ [0]
│ └─ { readonly id: string; readonly text: a string at most 50 character(s) long }
│ └─ ["text"]
│ └─ error_required_field
└─ [2]
└─ { readonly id: string; readonly text: a string at most 50 character(s) long }
└─ ["text"]
└─ error_max_length_field
*/

Error messages can go beyond simple strings by returning an Effect, allowing them to access dependencies, such as an internationalization service. This approach lets messages dynamically adjust based on external context or services. Below is an example illustrating how to create effect-based messages.

Example (Effect-Based Message with Internationalization Service)

import {
import Context

@since2.0.0

@since2.0.0

Context
,
import Effect

@since2.0.0

@since2.0.0

@since2.0.0

Effect
,
import Either

@since2.0.0

@since2.0.0

Either
,
import Option

@since2.0.0

@since2.0.0

Option
,
import Schema
Schema
,
import ParseResult
ParseResult
} from "effect"
// Define an internationalization service for custom messages
class
class Messages
Messages
extends
import Context

@since2.0.0

@since2.0.0

Context
.
const Tag: <"Messages">(id: "Messages") => <Self, Shape>() => Context.TagClass<Self, "Messages", Shape>

@example

import { Context, Layer } from "effect"
class MyTag extends Context.Tag("MyTag")<
MyTag,
{ readonly myNum: number }
>() {
static Live = Layer.succeed(this, { myNum: 108 })
}

@since2.0.0

Tag
("Messages")<
class Messages
Messages
,
{
type NonEmpty: string
NonEmpty
: string
}
>() {}
// Define a schema with an effect-based message
// that depends on the Messages service
const
const Name: Schema.refine<string, Schema.Schema<string, string, never>>
Name
=
import Schema
Schema
.
class NonEmptyString

@since3.10.0

NonEmptyString
.
Annotable<refine<string, Schema<string, string, never>>, string, string, never>.annotations(annotations: Schema.Annotations.GenericSchema<string>): Schema.refine<string, Schema.Schema<string, string, never>>

Merges a set of new annotations with existing ones, potentially overwriting any duplicates.

annotations
({
Annotations.Schema<string, readonly []>.message?: MessageAnnotation
message
: () =>
import Effect

@since2.0.0

@since2.0.0

@since2.0.0

Effect
.
const gen: <YieldWrap<Effect.Effect<Option.Option<{
NonEmpty: string;
}>, never, never>>, string>(f: (resume: Effect.Adapter) => Generator<YieldWrap<Effect.Effect<Option.Option<{
NonEmpty: string;
}>, never, never>>, string, never>) => Effect.Effect<...> (+1 overload)

Provides a way to write effectful code using generator functions, simplifying control flow and error handling.

When to Use

gen allows you to write code that looks and behaves like synchronous code, but it can handle asynchronous tasks, errors, and complex control flow (like loops and conditions). It helps make asynchronous code more readable and easier to manage.

The generator functions work similarly to async/await but with more explicit control over the execution of effects. You can yield* values from effects and return the final result at the end.

@example

import { Effect } from "effect"
const addServiceCharge = (amount: number) => amount + 1
const applyDiscount = (
total: number,
discountRate: number
): Effect.Effect<number, Error> =>
discountRate === 0
? Effect.fail(new Error("Discount rate cannot be zero"))
: Effect.succeed(total - (total * discountRate) / 100)
const fetchTransactionAmount = Effect.promise(() => Promise.resolve(100))
const fetchDiscountRate = Effect.promise(() => Promise.resolve(5))
export const program = Effect.gen(function* () {
const transactionAmount = yield* fetchTransactionAmount
const discountRate = yield* fetchDiscountRate
const discountedAmount = yield* applyDiscount(
transactionAmount,
discountRate
)
const finalAmount = addServiceCharge(discountedAmount)
return `Final amount to charge: ${finalAmount}`
})

@since2.0.0

gen
(function* (
_: Effect.Adapter
_
) {
// Attempt to retrieve the Messages service
const
const service: Option.Option<{
NonEmpty: string;
}>
service
= yield*
_: Effect.Adapter
<Option.Option<{
NonEmpty: string;
}>, never, never>(self: Effect.Effect<Option.Option<{
NonEmpty: string;
}>, never, never>) => Effect.Effect<Option.Option<{
NonEmpty: string;
}>, never, never> (+20 overloads)
_
(
import Effect

@since2.0.0

@since2.0.0

@since2.0.0

Effect
.
const serviceOption: <Messages, {
NonEmpty: string;
}>(tag: Context.Tag<Messages, {
NonEmpty: string;
}>) => Effect.Effect<Option.Option<{
NonEmpty: string;
}>, never, never>

@since2.0.0

serviceOption
(
class Messages
Messages
))
// Use a fallback message if the service is not available
return
import Option

@since2.0.0

@since2.0.0

Option
.
const match: <{
NonEmpty: string;
}, string, string>(self: Option.Option<{
NonEmpty: string;
}>, options: {
readonly onNone: LazyArg<string>;
readonly onSome: (a: {
NonEmpty: string;
}) => string;
}) => string (+1 overload)

Matches the given Option and returns either the provided onNone value or the result of the provided onSome function when passed the Option's value.

@paramself - The Option to match

@paramonNone - The value to be returned if the Option is None

@paramonSome - The function to be called if the Option is Some, it will be passed the Option's value and its result will be returned

@example

import { pipe, Option } from "effect"
assert.deepStrictEqual(
pipe(Option.some(1), Option.match({ onNone: () => 'a none', onSome: (a) => `a some containing ${a}` })),
'a some containing 1'
)
assert.deepStrictEqual(
pipe(Option.none(), Option.match({ onNone: () => 'a none', onSome: (a) => `a some containing ${a}` })),
'a none'
)

@since2.0.0

match
(
const service: Option.Option<{
NonEmpty: string;
}>
service
, {
onNone: LazyArg<string>
onNone
: () => "Invalid string",
onSome: (a: {
NonEmpty: string;
}) => string
onSome
: (
messages: {
NonEmpty: string;
}
messages
) =>
messages: {
NonEmpty: string;
}
messages
.
type NonEmpty: string
NonEmpty
})
})
})
// Attempt to decode an empty string without providing the Messages service
import Schema
Schema
.
const decodeUnknownEither: <string, string>(schema: Schema.Schema<string, string, never>, options?: ParseOptions) => (u: unknown, overrideOptions?: ParseOptions) => Either.Either<...>

@since3.10.0

decodeUnknownEither
(
const Name: Schema.refine<string, Schema.Schema<string, string, never>>
Name
)("").
Pipeable.pipe<Either.Either<string, ParseResult.ParseError>, Either.Either<string, void>>(this: Either.Either<...>, ab: (_: Either.Either<string, ParseResult.ParseError>) => Either.Either<...>): Either.Either<...> (+21 overloads)
pipe
(
import Either

@since2.0.0

@since2.0.0

Either
.
const mapLeft: <ParseResult.ParseError, void>(f: (left: ParseResult.ParseError) => void) => <R>(self: Either.Either<R, ParseResult.ParseError>) => Either.Either<...> (+1 overload)

Maps the Left side of an Either value to a new Either value.

@paramself - The input Either value to map.

@paramf - A transformation function to apply to the Left value of the input Either.

@since2.0.0

mapLeft
((
error: ParseResult.ParseError
error
) =>
import ParseResult
ParseResult
.
const TreeFormatter: ParseResult.ParseResultFormatter<string>

@since3.10.0

TreeFormatter
.
ParseResultFormatter<string>.formatError: (error: ParseResult.ParseError) => Effect.Effect<string, never, never>
formatError
(
error: ParseResult.ParseError
error
).
Pipeable.pipe<Effect.Effect<string, never, never>, string, void>(this: Effect.Effect<string, never, never>, ab: (_: Effect.Effect<string, never, never>) => string, bc: (_: string) => void): void (+21 overloads)
pipe
(
import Effect

@since2.0.0

@since2.0.0

@since2.0.0

Effect
.
const runSync: <A, E>(effect: Effect.Effect<A, E>) => A

Executes an effect synchronously, running it immediately and returning the result.

When to Use

Use runSync to run an effect that does not fail and does not include any asynchronous operations.

If the effect fails or involves asynchronous work, it will throw an error, and execution will stop where the failure or async operation occurs.

@seerunSyncExit for a version that returns an Exit type instead of throwing an error.

@example

// Title: Synchronous Logging
import { Effect } from "effect"
const program = Effect.sync(() => {
console.log("Hello, World!")
return 1
})
const result = Effect.runSync(program)
// Output: Hello, World!
console.log(result)
// Output: 1

@example

// Title: Incorrect Usage with Failing or Async Effects import { Effect } from "effect"

try { // Attempt to run an effect that fails Effect.runSync(Effect.fail("my error")) } catch (e) { console.error(e) } // Output: // (FiberFailure) Error: my error

try { // Attempt to run an effect that involves async work Effect.runSync(Effect.promise(() => Promise.resolve(1))) } catch (e) { console.error(e) } // Output: // (FiberFailure) AsyncFiberException: Fiber #0 cannot be resolved synchronously. This is caused by using runSync on an effect that performs async work

@since2.0.0

runSync
,
var console: Console

The console module provides a simple debugging console that is similar to the JavaScript console mechanism provided by web browsers.

The module exports two specific components:

  • A Console class with methods such as console.log(), console.error() and console.warn() that can be used to write to any Node.js stream.
  • A global console instance configured to write to process.stdout and process.stderr. The global console can be used without importing the node:console module.

Warning: The global console object's methods are neither consistently synchronous like the browser APIs they resemble, nor are they consistently asynchronous like all other Node.js streams. See the note on process I/O for more information.

Example using the global console:

console.log('hello world');
// Prints: hello world, to stdout
console.log('hello %s', 'world');
// Prints: hello world, to stdout
console.error(new Error('Whoops, something bad happened'));
// Prints error message and stack trace to stderr:
// Error: Whoops, something bad happened
// at [eval]:5:15
// at Script.runInThisContext (node:vm:132:18)
// at Object.runInThisContext (node:vm:309:38)
// at node:internal/process/execution:77:19
// at [eval]-wrapper:6:22
// at evalScript (node:internal/process/execution:76:60)
// at node:internal/main/eval_string:23:3
const name = 'Will Robinson';
console.warn(`Danger ${name}! Danger!`);
// Prints: Danger Will Robinson! Danger!, to stderr

Example using the Console class:

const out = getStreamSomehow();
const err = getStreamSomehow();
const myConsole = new console.Console(out, err);
myConsole.log('hello world');
// Prints: hello world, to out
myConsole.log('hello %s', 'world');
// Prints: hello world, to out
myConsole.error(new Error('Whoops, something bad happened'));
// Prints: [Error: Whoops, something bad happened], to err
const name = 'Will Robinson';
myConsole.warn(`Danger ${name}! Danger!`);
// Prints: Danger Will Robinson! Danger!, to err

@seesource

console
.
Console.log(message?: any, ...optionalParams: any[]): void

Prints to stdout with newline. Multiple arguments can be passed, with the first used as the primary message and all additional used as substitution values similar to printf(3) (the arguments are all passed to util.format()).

const count = 5;
console.log('count: %d', count);
// Prints: count: 5, to stdout
console.log('count:', count);
// Prints: count: 5, to stdout

See util.format() for more information.

@sincev0.1.100

log
)
)
)
// Output: Invalid string
// Provide the Messages service to customize the error message
import Schema
Schema
.
const decodeUnknownEither: <string, string>(schema: Schema.Schema<string, string, never>, options?: ParseOptions) => (u: unknown, overrideOptions?: ParseOptions) => Either.Either<...>

@since3.10.0

decodeUnknownEither
(
const Name: Schema.refine<string, Schema.Schema<string, string, never>>
Name
)("").
Pipeable.pipe<Either.Either<string, ParseResult.ParseError>, Either.Either<string, void>>(this: Either.Either<...>, ab: (_: Either.Either<string, ParseResult.ParseError>) => Either.Either<...>): Either.Either<...> (+21 overloads)
pipe
(
import Either

@since2.0.0

@since2.0.0

Either
.
const mapLeft: <ParseResult.ParseError, void>(f: (left: ParseResult.ParseError) => void) => <R>(self: Either.Either<R, ParseResult.ParseError>) => Either.Either<...> (+1 overload)

Maps the Left side of an Either value to a new Either value.

@paramself - The input Either value to map.

@paramf - A transformation function to apply to the Left value of the input Either.

@since2.0.0

mapLeft
((
error: ParseResult.ParseError
error
) =>
import ParseResult
ParseResult
.
const TreeFormatter: ParseResult.ParseResultFormatter<string>

@since3.10.0

TreeFormatter
.
ParseResultFormatter<string>.formatError: (error: ParseResult.ParseError) => Effect.Effect<string, never, never>
formatError
(
error: ParseResult.ParseError
error
).
Pipeable.pipe<Effect.Effect<string, never, never>, Effect.Effect<string, never, never>, string, void>(this: Effect.Effect<...>, ab: (_: Effect.Effect<string, never, never>) => Effect.Effect<string, never, never>, bc: (_: Effect.Effect<...>) => string, cd: (_: string) => void): void (+21 overloads)
pipe
(
import Effect

@since2.0.0

@since2.0.0

@since2.0.0

Effect
.
const provideService: <typeof Messages>(tag: typeof Messages, service: {
NonEmpty: string;
}) => <A, E, R>(self: Effect.Effect<A, E, R>) => Effect.Effect<A, E, Exclude<R, Messages>> (+1 overload)

The provideService function is used to provide an actual implementation for a service in the context of an effect.

This function allows you to associate a service with its implementation so that it can be used in your program. You define the service (e.g., a random number generator), and then you use provideService to link that service to its implementation. Once the implementation is provided, the effect can be run successfully without further requirements.

@seeprovide for providing multiple layers to an effect.

@example

import { Effect, Context } from "effect"
// Declaring a tag for a service that generates random numbers
class Random extends Context.Tag("MyRandomService")<
Random,
{ readonly next: Effect.Effect<number> }
>() {}
// Using the service
const program = Effect.gen(function* () {
const random = yield* Random
const randomNumber = yield* random.next
console.log(`random number: ${randomNumber}`)
})
// Providing the implementation
//
// ┌─── Effect<void, never, never>
// ▼
const runnable = Effect.provideService(program, Random, {
next: Effect.sync(() => Math.random())
})
// Run successfully
Effect.runPromise(runnable)
// Example Output:
// random number: 0.8241872233134417

@since2.0.0

provideService
(
class Messages
Messages
, {
type NonEmpty: string
NonEmpty
: "should be non empty"
}),
import Effect

@since2.0.0

@since2.0.0

@since2.0.0

Effect
.
const runSync: <A, E>(effect: Effect.Effect<A, E>) => A

Executes an effect synchronously, running it immediately and returning the result.

When to Use

Use runSync to run an effect that does not fail and does not include any asynchronous operations.

If the effect fails or involves asynchronous work, it will throw an error, and execution will stop where the failure or async operation occurs.

@seerunSyncExit for a version that returns an Exit type instead of throwing an error.

@example

// Title: Synchronous Logging
import { Effect } from "effect"
const program = Effect.sync(() => {
console.log("Hello, World!")
return 1
})
const result = Effect.runSync(program)
// Output: Hello, World!
console.log(result)
// Output: 1

@example

// Title: Incorrect Usage with Failing or Async Effects import { Effect } from "effect"

try { // Attempt to run an effect that fails Effect.runSync(Effect.fail("my error")) } catch (e) { console.error(e) } // Output: // (FiberFailure) Error: my error

try { // Attempt to run an effect that involves async work Effect.runSync(Effect.promise(() => Promise.resolve(1))) } catch (e) { console.error(e) } // Output: // (FiberFailure) AsyncFiberException: Fiber #0 cannot be resolved synchronously. This is caused by using runSync on an effect that performs async work

@since2.0.0

runSync
,
var console: Console

The console module provides a simple debugging console that is similar to the JavaScript console mechanism provided by web browsers.

The module exports two specific components:

  • A Console class with methods such as console.log(), console.error() and console.warn() that can be used to write to any Node.js stream.
  • A global console instance configured to write to process.stdout and process.stderr. The global console can be used without importing the node:console module.

Warning: The global console object's methods are neither consistently synchronous like the browser APIs they resemble, nor are they consistently asynchronous like all other Node.js streams. See the note on process I/O for more information.

Example using the global console:

console.log('hello world');
// Prints: hello world, to stdout
console.log('hello %s', 'world');
// Prints: hello world, to stdout
console.error(new Error('Whoops, something bad happened'));
// Prints error message and stack trace to stderr:
// Error: Whoops, something bad happened
// at [eval]:5:15
// at Script.runInThisContext (node:vm:132:18)
// at Object.runInThisContext (node:vm:309:38)
// at node:internal/process/execution:77:19
// at [eval]-wrapper:6:22
// at evalScript (node:internal/process/execution:76:60)
// at node:internal/main/eval_string:23:3
const name = 'Will Robinson';
console.warn(`Danger ${name}! Danger!`);
// Prints: Danger Will Robinson! Danger!, to stderr

Example using the Console class:

const out = getStreamSomehow();
const err = getStreamSomehow();
const myConsole = new console.Console(out, err);
myConsole.log('hello world');
// Prints: hello world, to out
myConsole.log('hello %s', 'world');
// Prints: hello world, to out
myConsole.error(new Error('Whoops, something bad happened'));
// Prints: [Error: Whoops, something bad happened], to err
const name = 'Will Robinson';
myConsole.warn(`Danger ${name}! Danger!`);
// Prints: Danger Will Robinson! Danger!, to err

@seesource

console
.
Console.log(message?: any, ...optionalParams: any[]): void

Prints to stdout with newline. Multiple arguments can be passed, with the first used as the primary message and all additional used as substitution values similar to printf(3) (the arguments are all passed to util.format()).

const count = 5;
console.log('count: %d', count);
// Prints: count: 5, to stdout
console.log('count:', count);
// Prints: count: 5, to stdout

See util.format() for more information.

@sincev0.1.100

log
)
)
)
// Output: should be non empty

You can provide custom messages for missing fields or tuple elements using the missingMessage annotation.

Example (Custom Message for Missing Property)

In this example, a custom message is defined for a missing name property in the Person schema.

import {
import Schema
Schema
} from "effect"
const
const Person: Schema.Struct<{
name: Schema.propertySignature<typeof Schema.String>;
}>
Person
=
import Schema
Schema
.
function Struct<{
name: Schema.propertySignature<typeof Schema.String>;
}>(fields: {
name: Schema.propertySignature<typeof Schema.String>;
}): Schema.Struct<{
name: Schema.propertySignature<typeof Schema.String>;
}> (+1 overload)

@since3.10.0

Struct
({
name: Schema.propertySignature<typeof Schema.String>
name
:
import Schema
Schema
.
const propertySignature: <typeof Schema.String>(self: typeof Schema.String) => Schema.propertySignature<typeof Schema.String>

Lifts a Schema into a PropertySignature.

@since3.10.0

propertySignature
(
import Schema
Schema
.
class String
export String

@since3.10.0

String
).
propertySignature<typeof String$>.annotations(annotations: Schema.PropertySignature<TypeToken extends Schema.PropertySignature.Token, Type, Key extends PropertyKey, EncodedToken extends Schema.PropertySignature.Token, Encoded, HasDefault extends boolean = false, R = never>.Annotations<string>): Schema.propertySignature<...>
annotations
({
// Custom message if "name" is missing
PropertySignature<TypeToken extends PropertySignature.Token, Type, Key extends PropertyKey, EncodedToken extends PropertySignature.Token, Encoded, HasDefault extends boolean = false, R = never>.Annotations<string>.missingMessage?: MissingMessageAnnotation
missingMessage
: () => "Name is required"
})
})
import Schema
Schema
.
decodeUnknownSync<{
readonly name: string;
}, {
readonly name: string;
}>(schema: Schema.Schema<{
readonly name: string;
}, {
readonly name: string;
}, never>, options?: ParseOptions): (u: unknown, overrideOptions?: ParseOptions) => {
readonly name: string;
}
export decodeUnknownSync

@throwsParseError

@since3.10.0

decodeUnknownSync
(
const Person: Schema.Struct<{
name: Schema.propertySignature<typeof Schema.String>;
}>
Person
)({})
/*
throws:
ParseError: { readonly name: string }
└─ ["name"]
└─ Name is required
*/

Example (Custom Message for Missing Tuple Elements)

Here, each element in the Point tuple schema has a specific custom message if the element is missing.

import {
import Schema
Schema
} from "effect"
const
const Point: Schema.Tuple<[Schema.Element<typeof Schema.Number, "">, Schema.Element<typeof Schema.Number, "">]>
Point
=
import Schema
Schema
.
function Tuple<[Schema.Element<typeof Schema.Number, "">, Schema.Element<typeof Schema.Number, "">]>(elements_0: Schema.Element<typeof Schema.Number, "">, elements_1: Schema.Element<...>): Schema.Tuple<...> (+1 overload)

@since3.10.0

Tuple
(
import Schema
Schema
.
const element: <typeof Schema.Number>(self: typeof Schema.Number) => Schema.Element<typeof Schema.Number, "">

@since3.10.0

element
(
import Schema
Schema
.
class Number
export Number

@since3.10.0

Number
).
Element<typeof Number$, "">.annotations(annotations: Schema.Element<S extends Schema.Schema<in out A, in out I = A, out R = never>.Any, Token extends Schema.Element.Token>.Annotations<number>): Schema.Element<typeof Schema.Number, "">
annotations
({
// Message if X is missing
Element<S extends Schema<in out A, in out I = A, out R = never>.Any, Token extends Element.Token>.Annotations<number>.missingMessage?: MissingMessageAnnotation
missingMessage
: () => "X coordinate is required"
}),
import Schema
Schema
.
const element: <typeof Schema.Number>(self: typeof Schema.Number) => Schema.Element<typeof Schema.Number, "">

@since3.10.0

element
(
import Schema
Schema
.
class Number
export Number

@since3.10.0

Number
).
Element<typeof Number$, "">.annotations(annotations: Schema.Element<S extends Schema.Schema<in out A, in out I = A, out R = never>.Any, Token extends Schema.Element.Token>.Annotations<number>): Schema.Element<typeof Schema.Number, "">
annotations
({
// Message if Y is missing
Element<S extends Schema<in out A, in out I = A, out R = never>.Any, Token extends Element.Token>.Annotations<number>.missingMessage?: MissingMessageAnnotation
missingMessage
: () => "Y coordinate is required"
})
)
import Schema
Schema
.
decodeUnknownSync<readonly [number, number], readonly [number, number]>(schema: Schema.Schema<readonly [number, number], readonly [number, number], never>, options?: ParseOptions): (u: unknown, overrideOptions?: ParseOptions) => readonly [...]
export decodeUnknownSync

@throwsParseError

@since3.10.0

decodeUnknownSync
(
const Point: Schema.Tuple<[Schema.Element<typeof Schema.Number, "">, Schema.Element<typeof Schema.Number, "">]>
Point
)([], {
ParseOptions.errors?: "first" | "all" | undefined

The errors option allows you to receive all parsing errors when attempting to parse a value using a schema. By default only the first error is returned, but by setting the errors option to "all", you can receive all errors that occurred during the parsing process. This can be useful for debugging or for providing more comprehensive error messages to the user.

default: "first"

@since3.10.0

errors
: "all" })
/*
throws:
ParseError: readonly [number, number]
├─ [0]
│ └─ X coordinate is required
└─ [1]
└─ Y coordinate is required
*/