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)

1
import {
import Schema
Schema
} from "effect"
2
3
const
const schema: Schema.Struct<{ name: typeof Schema.String; age: typeof Schema.Number; }>
schema
=
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) namespace Struct
Struct
({
4
(property) name: typeof Schema.String
name
:
import Schema
Schema
.
(alias) class String export String
String
,
5
(property) age: typeof Schema.Number
age
:
import Schema
Schema
.
(alias) class Number export Number
Number
6
})
7
8
import Schema
Schema
.
(alias) 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
decodeUnknownSync
(
const schema: Schema.Struct<{ name: typeof Schema.String; age: typeof Schema.Number; }>
schema
)(null)
9
/*
10
ParseError: Date
11
└─ Predicate refinement failure
12
└─ Expected Date, actual Invalid Date
13
*/

Example (Missing Properties)

1
import {
import Schema
Schema
} from "effect"
2
3
const
const schema: Schema.Struct<{ name: typeof Schema.String; age: typeof Schema.Number; }>
schema
=
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) namespace Struct
Struct
({
4
(property) name: typeof Schema.String
name
:
import Schema
Schema
.
(alias) class String export String
String
,
5
(property) age: typeof Schema.Number
age
:
import Schema
Schema
.
(alias) class Number export Number
Number
6
})
7
8
import Schema
Schema
.
(alias) 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
decodeUnknownSync
(
const schema: Schema.Struct<{ name: typeof Schema.String; age: typeof Schema.Number; }>
schema
)({}, {
(property) 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"

errors
: "all" })
9
/*
10
throws:
11
ParseError: { readonly name: string; readonly age: number }
12
├─ ["name"]
13
│ └─ is missing
14
└─ ["age"]
15
└─ is missing
16
*/

Example (Incorrect Property Type)

1
import {
import Schema
Schema
} from "effect"
2
3
const
const schema: Schema.Struct<{ name: typeof Schema.String; age: typeof Schema.Number; }>
schema
=
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) namespace Struct
Struct
({
4
(property) name: typeof Schema.String
name
:
import Schema
Schema
.
(alias) class String export String
String
,
5
(property) age: typeof Schema.Number
age
:
import Schema
Schema
.
(alias) class Number export Number
Number
6
})
7
8
import Schema
Schema
.
(alias) 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
decodeUnknownSync
(
const schema: Schema.Struct<{ name: typeof Schema.String; age: typeof Schema.Number; }>
schema
)(
9
{
(property) name: null
name
: null,
(property) age: string
age
: "age" },
10
{
(property) 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"

errors
: "all" }
11
)
12
/*
13
throws:
14
ParseError: { readonly name: string; readonly age: number }
15
├─ ["name"]
16
│ └─ Expected string, actual null
17
└─ ["age"]
18
└─ Expected number, actual "age"
19
*/

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

1
import {
import Schema
Schema
} from "effect"
2
3
const
const Name: Schema.SchemaClass<string, string, never>
Name
=
import Schema
Schema
.
(alias) class String export String
String
.
(method) Annotable<SchemaClass<string, string, never>, string, string, never>.annotations(annotations: Schema.Annotations.Schema<string, readonly []>): Schema.SchemaClass<string, string, never>

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

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

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

annotations
({
(property) Annotations.Schema<A, TypeParameters extends ReadonlyArray<any> = readonly []>.identifier?: string
identifier
: "Age" })
6
7
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<...>; }): Schema.Struct<...> (+1 overload) namespace Struct
Struct
({
8
(property) name: Schema.SchemaClass<string, string, never>
name
:
const Name: Schema.SchemaClass<string, string, never>
Name
,
9
(property) age: Schema.SchemaClass<number, number, never>
age
:
const Age: Schema.SchemaClass<number, number, never>
Age
10
}).
(method) 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
({
(property) Annotations.Schema<A, TypeParameters extends ReadonlyArray<any> = readonly []>.identifier?: string
identifier
: "Person" })
11
12
import Schema
Schema
.
(alias) 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
decodeUnknownSync
(
const Person: Schema.Struct<{ name: Schema.SchemaClass<string, string, never>; age: Schema.SchemaClass<number, number, never>; }>
Person
)(null)
13
/*
14
throws:
15
ParseError: Expected Person, actual null
16
*/
17
18
import Schema
Schema
.
(alias) 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
decodeUnknownSync
(
const Person: Schema.Struct<{ name: Schema.SchemaClass<string, string, never>; age: Schema.SchemaClass<number, number, never>; }>
Person
)({}, {
(property) 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"

errors
: "all" })
19
/*
20
throws:
21
ParseError: Person
22
├─ ["name"]
23
│ └─ is missing
24
└─ ["age"]
25
└─ is missing
26
*/
27
28
import Schema
Schema
.
(alias) 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
decodeUnknownSync
(
const Person: Schema.Struct<{ name: Schema.SchemaClass<string, string, never>; age: Schema.SchemaClass<number, number, never>; }>
Person
)(
29
{
(property) name: null
name
: null,
(property) age: null
age
: null },
30
{
(property) 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"

errors
: "all" }
31
)
32
/*
33
throws:
34
ParseError: Person
35
├─ ["name"]
36
│ └─ Expected Name, actual null
37
└─ ["age"]
38
└─ Expected Age, actual null
39
*/

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

1
import {
import Schema
Schema
} from "effect"
2
3
const
const Name: Schema.refine<string, Schema.Schema<string, string, never>>
Name
=
import Schema
Schema
.
class NonEmptyString
NonEmptyString
.
(method) Annotable<refine<string, Schema<string, string, never>>, string, string, never>.annotations(annotations: Schema.Annotations.Schema<string, readonly []>): Schema.refine<string, Schema.Schema<string, string, never>>

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

annotations
({
(property) Annotations.Schema<string, readonly []>.identifier?: string
identifier
: "Name" }) // refinement
4
5
const
const Age: Schema.filter<Schema.Schema<number, number, never>>
Age
=
import Schema
Schema
.
class Positive
Positive
.
(method) 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>>
int
({
(property) Annotations.Schema<A, TypeParameters extends ReadonlyArray<any> = readonly []>.identifier?: string
identifier
: "Age" })) // refinement
6
7
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<...>; age: Schema.filter<...>; }): Schema.Struct<...> (+1 overload) namespace Struct
Struct
({
8
(property) name: Schema.refine<string, Schema.Schema<string, string, never>>
name
:
const Name: Schema.refine<string, Schema.Schema<string, string, never>>
Name
,
9
(property) age: Schema.filter<Schema.Schema<number, number, never>>
age
:
const Age: Schema.filter<Schema.Schema<number, number, never>>
Age
10
}).
(method) 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
({
(property) Annotations.Schema<A, TypeParameters extends ReadonlyArray<any> = readonly []>.identifier?: string
identifier
: "Person" })
11
12
// From side failure
13
import Schema
Schema
.
(alias) 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
decodeUnknownSync
(
const Person: Schema.Struct<{ name: Schema.refine<string, Schema.Schema<string, string, never>>; age: Schema.filter<Schema.Schema<number, number, never>>; }>
Person
)({
(property) name: null
name
: null,
(property) age: number
age
: 18 })
14
/*
15
throws:
16
ParseError: Person
17
└─ ["name"]
18
└─ Name
19
└─ From side refinement failure
20
└─ Expected string, actual null
21
*/
22
23
// Predicate refinement failure
24
import Schema
Schema
.
(alias) 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
decodeUnknownSync
(
const Person: Schema.Struct<{ name: Schema.refine<string, Schema.Schema<string, string, never>>; age: Schema.filter<Schema.Schema<number, number, never>>; }>
Person
)({
(property) name: string
name
: "",
(property) age: number
age
: 18 })
25
/*
26
throws:
27
ParseError: Person
28
└─ ["name"]
29
└─ Name
30
└─ Predicate refinement failure
31
└─ Expected Name, actual ""
32
*/

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

1
import {
import ParseResult
ParseResult
,
import Schema
Schema
} from "effect"
2
3
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.

transformOrFail
(
4
import Schema
Schema
.
(alias) class String export String
String
,
5
import Schema
Schema
.
(alias) class String export String
String
.
(method) 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<...>
minLength
(2)),
6
{
7
(property) strict?: true
strict
: true,
8
(property) decode: (fromA: string, options: ParseOptions, ast: Transformation, fromI: string) => Effect<string, ParseResult.ParseIssue, never>
decode
: (
(parameter) s: string
s
,
(parameter) _: ParseOptions
_
,
(parameter) ast: Transformation
ast
) =>
9
(parameter) s: string
s
.
(property) String.length: number

Returns the length of a String object.

length
> 0
10
?
import ParseResult
ParseResult
.
const succeed: <string>(a: string) => Either<string, ParseResult.ParseIssue>
succeed
(
(parameter) s: string
s
)
11
:
import ParseResult
ParseResult
.
const fail: (issue: ParseResult.ParseIssue) => Either<never, ParseResult.ParseIssue>
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.

Type
(
(parameter) ast: Transformation
ast
,
(parameter) s: string
s
)),
12
(property) 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>
succeed
13
}
14
)
15
16
// Encoded side failure
17
import Schema
Schema
.
(alias) decodeUnknownSync<string, string>(schema: Schema.Schema<string, string, never>, options?: ParseOptions): (u: unknown, overrideOptions?: ParseOptions) => string export decodeUnknownSync
decodeUnknownSync
(
const schema: Schema.transformOrFail<typeof Schema.String, Schema.filter<Schema.Schema<string, string, never>>, never>
schema
)(null)
18
/*
19
throws:
20
ParseError: (string <-> a string at least 2 character(s) long)
21
└─ Encoded side transformation failure
22
└─ Expected string, actual null
23
*/
24
25
// transformation failure
26
import Schema
Schema
.
(alias) decodeUnknownSync<string, string>(schema: Schema.Schema<string, string, never>, options?: ParseOptions): (u: unknown, overrideOptions?: ParseOptions) => string export decodeUnknownSync
decodeUnknownSync
(
const schema: Schema.transformOrFail<typeof Schema.String, Schema.filter<Schema.Schema<string, string, never>>, never>
schema
)("")
27
/*
28
throws:
29
ParseError: (string <-> a string at least 2 character(s) long)
30
└─ Transformation process failure
31
└─ Expected (string <-> a string at least 2 character(s) long), actual ""
32
*/
33
34
// Type side failure
35
import Schema
Schema
.
(alias) decodeUnknownSync<string, string>(schema: Schema.Schema<string, string, never>, options?: ParseOptions): (u: unknown, overrideOptions?: ParseOptions) => string export decodeUnknownSync
decodeUnknownSync
(
const schema: Schema.transformOrFail<typeof Schema.String, Schema.filter<Schema.Schema<string, string, never>>, never>
schema
)("a")
36
/*
37
throws:
38
ParseError: (string <-> a string at least 2 character(s) long)
39
└─ Type side transformation failure
40
└─ a string at least 2 character(s) long
41
└─ Predicate refinement failure
42
└─ Expected a string at least 2 character(s) long, actual "a"
43
*/

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

1
import {
import Schema
Schema
} from "effect"
2
3
const
const MyString: Schema.SchemaClass<string, string, never>
MyString
=
import Schema
Schema
.
(alias) class String export String
String
.
(method) Annotable<SchemaClass<string, string, never>, string, string, never>.annotations(annotations: Schema.Annotations.Schema<string, readonly []>): Schema.SchemaClass<string, string, never>

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

annotations
({
4
(property) Annotations.Schema<string, readonly []>.message?: MessageAnnotation
message
: () => "my custom message"
5
})
6
7
import Schema
Schema
.
(alias) decodeUnknownSync<string, string>(schema: Schema.Schema<string, string, never>, options?: ParseOptions): (u: unknown, overrideOptions?: ParseOptions) => string export decodeUnknownSync
decodeUnknownSync
(
const MyString: Schema.SchemaClass<string, string, never>
MyString
)(null)
8
/*
9
throws:
10
ParseError: my custom message
11
*/

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.

1
import {
import Schema
Schema
} from "effect"
2
3
const
const MyString: Schema.SchemaClass<string, string, never>
MyString
=
import Schema
Schema
.
(alias) class String export String
String
.
(method) Annotable<SchemaClass<string, string, never>, string, string, never>.annotations(annotations: Schema.Annotations.Schema<string, readonly []>): Schema.SchemaClass<string, string, never>

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

annotations
({
4
(property) Annotations.Schema<string, readonly []>.message?: MessageAnnotation
message
: () => "my custom message"
5
})
6
7
const
const decode: (u: unknown, overrideOptions?: ParseOptions) => string
decode
=
import Schema
Schema
.
(alias) decodeUnknownSync<string, string>(schema: Schema.Schema<string, string, never>, options?: ParseOptions): (u: unknown, overrideOptions?: ParseOptions) => string export decodeUnknownSync
decodeUnknownSync
(
const MyString: Schema.SchemaClass<string, string, never>
MyString
)
8
9
try {
10
const decode: (u: unknown, overrideOptions?: ParseOptions) => string
decode
(null)
11
} catch (
var e: any
e
: any) {
12
namespace console 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`](https://nodejs.org/docs/latest-v22.x/api/process.html#processstdout) and [`process.stderr`](https://nodejs.org/docs/latest-v22.x/api/process.html#processstderr). 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`](https://nodejs.org/docs/latest-v22.x/api/process.html#a-note-on-process-io) for more information. Example using the global `console`: ```js 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: ```js 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 ```

console
.
(method) 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)`](http://man7.org/linux/man-pages/man3/printf.3.html) (the arguments are all passed to [`util.format()`](https://nodejs.org/docs/latest-v22.x/api/util.html#utilformatformat-args)). ```js 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()`](https://nodejs.org/docs/latest-v22.x/api/util.html#utilformatformat-args) for more information.

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

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.

1
import {
import Schema
Schema
} from "effect"
2
3
const
const MyString: Schema.refine<string, Schema.Schema<string, string, never>>
MyString
=
import Schema
Schema
.
(alias) class String export String
String
.
(method) 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
(
4
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<...>
minLength
(1),
5
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<...>
maxLength
(2)
6
).
(method) Annotable<refine<string, Schema<string, string, never>>, string, string, never>.annotations(annotations: Schema.Annotations.Schema<string, readonly []>): Schema.refine<string, Schema.Schema<string, string, never>>

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

annotations
({
7
// This message is displayed only if the last filter (`maxLength`) fails
8
(property) Annotations.Schema<A, TypeParameters extends ReadonlyArray<any> = readonly []>.message?: MessageAnnotation
message
: () => "my custom message"
9
})
10
11
const
const decode: (u: unknown, overrideOptions?: ParseOptions) => string
decode
=
import Schema
Schema
.
(alias) decodeUnknownSync<string, string>(schema: Schema.Schema<string, string, never>, options?: ParseOptions): (u: unknown, overrideOptions?: ParseOptions) => string export decodeUnknownSync
decodeUnknownSync
(
const MyString: Schema.refine<string, Schema.Schema<string, string, never>>
MyString
)
12
13
try {
14
const decode: (u: unknown, overrideOptions?: ParseOptions) => string
decode
(null)
15
} catch (
var e: any
e
: any) {
16
namespace console 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`](https://nodejs.org/docs/latest-v22.x/api/process.html#processstdout) and [`process.stderr`](https://nodejs.org/docs/latest-v22.x/api/process.html#processstderr). 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`](https://nodejs.org/docs/latest-v22.x/api/process.html#a-note-on-process-io) for more information. Example using the global `console`: ```js 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: ```js 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 ```

console
.
(method) 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)`](http://man7.org/linux/man-pages/man3/printf.3.html) (the arguments are all passed to [`util.format()`](https://nodejs.org/docs/latest-v22.x/api/util.html#utilformatformat-args)). ```js 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()`](https://nodejs.org/docs/latest-v22.x/api/util.html#utilformatformat-args) for more information.

log
(
var e: any
e
.
any
message
)
17
/*
18
a string at most 2 character(s) long
19
└─ From side refinement failure
20
└─ a string at least 1 character(s) long
21
└─ From side refinement failure
22
└─ Expected string, actual null
23
*/
24
}
25
26
try {
27
const decode: (u: unknown, overrideOptions?: ParseOptions) => string
decode
("")
28
} catch (
var e: any
e
: any) {
29
namespace console 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`](https://nodejs.org/docs/latest-v22.x/api/process.html#processstdout) and [`process.stderr`](https://nodejs.org/docs/latest-v22.x/api/process.html#processstderr). 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`](https://nodejs.org/docs/latest-v22.x/api/process.html#a-note-on-process-io) for more information. Example using the global `console`: ```js 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: ```js 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 ```

console
.
(method) 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)`](http://man7.org/linux/man-pages/man3/printf.3.html) (the arguments are all passed to [`util.format()`](https://nodejs.org/docs/latest-v22.x/api/util.html#utilformatformat-args)). ```js 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()`](https://nodejs.org/docs/latest-v22.x/api/util.html#utilformatformat-args) for more information.

log
(
var e: any
e
.
any
message
)
30
/*
31
a string at most 2 character(s) long
32
└─ From side refinement failure
33
└─ a string at least 1 character(s) long
34
└─ Predicate refinement failure
35
└─ Expected a string at least 1 character(s) long, actual ""
36
*/
37
}
38
39
try {
40
const decode: (u: unknown, overrideOptions?: ParseOptions) => string
decode
("abc")
41
} catch (
var e: any
e
: any) {
42
namespace console 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`](https://nodejs.org/docs/latest-v22.x/api/process.html#processstdout) and [`process.stderr`](https://nodejs.org/docs/latest-v22.x/api/process.html#processstderr). 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`](https://nodejs.org/docs/latest-v22.x/api/process.html#a-note-on-process-io) for more information. Example using the global `console`: ```js 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: ```js 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 ```

console
.
(method) 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)`](http://man7.org/linux/man-pages/man3/printf.3.html) (the arguments are all passed to [`util.format()`](https://nodejs.org/docs/latest-v22.x/api/util.html#utilformatformat-args)). ```js 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()`](https://nodejs.org/docs/latest-v22.x/api/util.html#utilformatformat-args) for more information.

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

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

1
import {
import Schema
Schema
} from "effect"
2
3
const
const MyString: Schema.filter<Schema.Schema<string, string, never>>
MyString
=
import Schema
Schema
.
(alias) class String export String
String
4
// This message is displayed only if a non-String is passed as input
5
.
(method) Annotable<SchemaClass<string, string, never>, string, string, never>.annotations(annotations: Schema.Annotations.Schema<string, readonly []>): Schema.SchemaClass<string, string, never>

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

annotations
({
(property) Annotations.Schema<string, readonly []>.message?: MessageAnnotation
message
: () => "String custom message" })
6
.
(method) 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
(
7
// This message is displayed only if the filter `minLength` fails
8
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<...>
minLength
(1, {
(property) Annotations.Schema<A, TypeParameters extends ReadonlyArray<any> = readonly []>.message?: MessageAnnotation
message
: () => "minLength custom message" }),
9
// This message is displayed only if the filter `maxLength` fails
10
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<...>
maxLength
(2, {
(property) Annotations.Schema<A, TypeParameters extends ReadonlyArray<any> = readonly []>.message?: MessageAnnotation
message
: () => "maxLength custom message" })
11
)
12
13
const
const decode: (u: unknown, overrideOptions?: ParseOptions) => string
decode
=
import Schema
Schema
.
(alias) decodeUnknownSync<string, string>(schema: Schema.Schema<string, string, never>, options?: ParseOptions): (u: unknown, overrideOptions?: ParseOptions) => string export decodeUnknownSync
decodeUnknownSync
(
const MyString: Schema.filter<Schema.Schema<string, string, never>>
MyString
)
14
15
try {
16
const decode: (u: unknown, overrideOptions?: ParseOptions) => string
decode
(null)
17
} catch (
var e: any
e
: any) {
18
namespace console 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`](https://nodejs.org/docs/latest-v22.x/api/process.html#processstdout) and [`process.stderr`](https://nodejs.org/docs/latest-v22.x/api/process.html#processstderr). 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`](https://nodejs.org/docs/latest-v22.x/api/process.html#a-note-on-process-io) for more information. Example using the global `console`: ```js 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: ```js 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 ```

console
.
(method) 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)`](http://man7.org/linux/man-pages/man3/printf.3.html) (the arguments are all passed to [`util.format()`](https://nodejs.org/docs/latest-v22.x/api/util.html#utilformatformat-args)). ```js 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()`](https://nodejs.org/docs/latest-v22.x/api/util.html#utilformatformat-args) for more information.

log
(
var e: any
e
.
any
message
) // String custom message
19
}
20
21
try {
22
const decode: (u: unknown, overrideOptions?: ParseOptions) => string
decode
("")
23
} catch (
var e: any
e
: any) {
24
namespace console 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`](https://nodejs.org/docs/latest-v22.x/api/process.html#processstdout) and [`process.stderr`](https://nodejs.org/docs/latest-v22.x/api/process.html#processstderr). 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`](https://nodejs.org/docs/latest-v22.x/api/process.html#a-note-on-process-io) for more information. Example using the global `console`: ```js 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: ```js 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 ```

console
.
(method) 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)`](http://man7.org/linux/man-pages/man3/printf.3.html) (the arguments are all passed to [`util.format()`](https://nodejs.org/docs/latest-v22.x/api/util.html#utilformatformat-args)). ```js 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()`](https://nodejs.org/docs/latest-v22.x/api/util.html#utilformatformat-args) for more information.

log
(
var e: any
e
.
any
message
) // minLength custom message
25
}
26
27
try {
28
const decode: (u: unknown, overrideOptions?: ParseOptions) => string
decode
("abc")
29
} catch (
var e: any
e
: any) {
30
namespace console 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`](https://nodejs.org/docs/latest-v22.x/api/process.html#processstdout) and [`process.stderr`](https://nodejs.org/docs/latest-v22.x/api/process.html#processstderr). 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`](https://nodejs.org/docs/latest-v22.x/api/process.html#a-note-on-process-io) for more information. Example using the global `console`: ```js 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: ```js 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 ```

console
.
(method) 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)`](http://man7.org/linux/man-pages/man3/printf.3.html) (the arguments are all passed to [`util.format()`](https://nodejs.org/docs/latest-v22.x/api/util.html#utilformatformat-args)). ```js 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()`](https://nodejs.org/docs/latest-v22.x/api/util.html#utilformatformat-args) for more information.

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

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.

1
import {
import Schema
Schema
} from "effect"
2
3
const
const MyString: Schema.refine<string, Schema.Schema<string, string, never>>
MyString
=
import Schema
Schema
.
(alias) class String export String
String
.
(method) 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
(
4
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<...>
minLength
(1),
5
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<...>
maxLength
(2)
6
).
(method) Annotable<refine<string, Schema<string, string, never>>, string, string, never>.annotations(annotations: Schema.Annotations.Schema<string, readonly []>): Schema.refine<string, Schema.Schema<string, string, never>>

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

annotations
({
7
// By setting the `override` flag to `true`, this message will always be shown for any error
8
(property) Annotations.Schema<A, TypeParameters extends ReadonlyArray<any> = readonly []>.message?: MessageAnnotation
message
: () => ({
(property) message: string | Effect<string, never, never>
message
: "my custom message",
(property) override: boolean
override
: true })
9
})
10
11
const
const decode: (u: unknown, overrideOptions?: ParseOptions) => string
decode
=
import Schema
Schema
.
(alias) decodeUnknownSync<string, string>(schema: Schema.Schema<string, string, never>, options?: ParseOptions): (u: unknown, overrideOptions?: ParseOptions) => string export decodeUnknownSync
decodeUnknownSync
(
const MyString: Schema.refine<string, Schema.Schema<string, string, never>>
MyString
)
12
13
try {
14
const decode: (u: unknown, overrideOptions?: ParseOptions) => string
decode
(null)
15
} catch (
var e: any
e
: any) {
16
namespace console 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`](https://nodejs.org/docs/latest-v22.x/api/process.html#processstdout) and [`process.stderr`](https://nodejs.org/docs/latest-v22.x/api/process.html#processstderr). 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`](https://nodejs.org/docs/latest-v22.x/api/process.html#a-note-on-process-io) for more information. Example using the global `console`: ```js 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: ```js 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 ```

console
.
(method) 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)`](http://man7.org/linux/man-pages/man3/printf.3.html) (the arguments are all passed to [`util.format()`](https://nodejs.org/docs/latest-v22.x/api/util.html#utilformatformat-args)). ```js 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()`](https://nodejs.org/docs/latest-v22.x/api/util.html#utilformatformat-args) for more information.

log
(
var e: any
e
.
any
message
) // my custom message
17
}
18
19
try {
20
const decode: (u: unknown, overrideOptions?: ParseOptions) => string
decode
("")
21
} catch (
var e: any
e
: any) {
22
namespace console 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`](https://nodejs.org/docs/latest-v22.x/api/process.html#processstdout) and [`process.stderr`](https://nodejs.org/docs/latest-v22.x/api/process.html#processstderr). 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`](https://nodejs.org/docs/latest-v22.x/api/process.html#a-note-on-process-io) for more information. Example using the global `console`: ```js 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: ```js 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 ```

console
.
(method) 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)`](http://man7.org/linux/man-pages/man3/printf.3.html) (the arguments are all passed to [`util.format()`](https://nodejs.org/docs/latest-v22.x/api/util.html#utilformatformat-args)). ```js 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()`](https://nodejs.org/docs/latest-v22.x/api/util.html#utilformatformat-args) for more information.

log
(
var e: any
e
.
any
message
) // my custom message
23
}
24
25
try {
26
const decode: (u: unknown, overrideOptions?: ParseOptions) => string
decode
("abc")
27
} catch (
var e: any
e
: any) {
28
namespace console 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`](https://nodejs.org/docs/latest-v22.x/api/process.html#processstdout) and [`process.stderr`](https://nodejs.org/docs/latest-v22.x/api/process.html#processstderr). 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`](https://nodejs.org/docs/latest-v22.x/api/process.html#a-note-on-process-io) for more information. Example using the global `console`: ```js 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: ```js 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 ```

console
.
(method) 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)`](http://man7.org/linux/man-pages/man3/printf.3.html) (the arguments are all passed to [`util.format()`](https://nodejs.org/docs/latest-v22.x/api/util.html#utilformatformat-args)). ```js 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()`](https://nodejs.org/docs/latest-v22.x/api/util.html#utilformatformat-args) for more information.

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

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

1
import {
import ParseResult
ParseResult
,
import Schema
Schema
} from "effect"
2
3
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.

transformOrFail
(
4
// This message is displayed only if the input is not a string
5
import Schema
Schema
.
(alias) class String export String
String
.
(method) Annotable<SchemaClass<string, string, never>, string, string, never>.annotations(annotations: Schema.Annotations.Schema<string, readonly []>): Schema.SchemaClass<string, string, never>

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

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

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

annotations
({
(property) Annotations.Schema<A, TypeParameters extends ReadonlyArray<any> = readonly []>.message?: MessageAnnotation
message
: () => "please enter an integer" }),
8
{
9
(property) strict?: true
strict
: true,
10
(property) decode: (fromA: string, options: ParseOptions, ast: Transformation, fromI: string) => Effect<number, ParseResult.ParseIssue, never>
decode
: (
(parameter) s: string
s
,
(parameter) _: ParseOptions
_
,
(parameter) ast: Transformation
ast
) => {
11
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
(
(parameter) s: string
s
)
12
return
var Number: NumberConstructor

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

Number
.
(method) 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.

isNaN
(
const n: number
n
)
13
?
import ParseResult
ParseResult
.
const fail: (issue: ParseResult.ParseIssue) => Either<never, ParseResult.ParseIssue>
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.

Type
(
(parameter) ast: Transformation
ast
,
(parameter) s: string
s
))
14
:
import ParseResult
ParseResult
.
const succeed: <number>(a: number) => Either<number, ParseResult.ParseIssue>
succeed
(
const n: number
n
)
15
},
16
(property) encode: (toI: number, options: ParseOptions, ast: Transformation, toA: number) => Effect<string, ParseResult.ParseIssue, never>
encode
: (
(parameter) n: number
n
) =>
import ParseResult
ParseResult
.
const succeed: <string>(a: string) => Either<string, ParseResult.ParseIssue>
succeed
(
var String: StringConstructor (value?: any) => string

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

String
(
(parameter) n: number
n
))
17
}
18
)
19
// This message is displayed only if the input cannot be converted to a number
20
.
(method) Annotable<transformOrFail<SchemaClass<string, string, never>, refine<number, Schema<number, number, never>>, never>, number, string, never>.annotations(annotations: Schema.Annotations.Schema<number, readonly []>): 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
({
(property) Annotations.Schema<A, TypeParameters extends ReadonlyArray<any> = readonly []>.message?: MessageAnnotation
message
: () => "please enter a parseable string" })
21
22
const
const decode: (u: unknown, overrideOptions?: ParseOptions) => number
decode
=
import Schema
Schema
.
(alias) decodeUnknownSync<number, string>(schema: Schema.Schema<number, string, never>, options?: ParseOptions): (u: unknown, overrideOptions?: ParseOptions) => number export decodeUnknownSync
decodeUnknownSync
(
const IntFromString: Schema.transformOrFail<Schema.SchemaClass<string, string, never>, Schema.refine<number, Schema.Schema<number, number, never>>, never>
IntFromString
)
23
24
try {
25
const decode: (u: unknown, overrideOptions?: ParseOptions) => number
decode
(null)
26
} catch (
var e: any
e
: any) {
27
namespace console 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`](https://nodejs.org/docs/latest-v22.x/api/process.html#processstdout) and [`process.stderr`](https://nodejs.org/docs/latest-v22.x/api/process.html#processstderr). 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`](https://nodejs.org/docs/latest-v22.x/api/process.html#a-note-on-process-io) for more information. Example using the global `console`: ```js 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: ```js 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 ```

console
.
(method) 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)`](http://man7.org/linux/man-pages/man3/printf.3.html) (the arguments are all passed to [`util.format()`](https://nodejs.org/docs/latest-v22.x/api/util.html#utilformatformat-args)). ```js 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()`](https://nodejs.org/docs/latest-v22.x/api/util.html#utilformatformat-args) for more information.

log
(
var e: any
e
.
any
message
) // please enter a string
28
}
29
30
try {
31
const decode: (u: unknown, overrideOptions?: ParseOptions) => number
decode
("1.2")
32
} catch (
var e: any
e
: any) {
33
namespace console 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`](https://nodejs.org/docs/latest-v22.x/api/process.html#processstdout) and [`process.stderr`](https://nodejs.org/docs/latest-v22.x/api/process.html#processstderr). 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`](https://nodejs.org/docs/latest-v22.x/api/process.html#a-note-on-process-io) for more information. Example using the global `console`: ```js 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: ```js 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 ```

console
.
(method) 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)`](http://man7.org/linux/man-pages/man3/printf.3.html) (the arguments are all passed to [`util.format()`](https://nodejs.org/docs/latest-v22.x/api/util.html#utilformatformat-args)). ```js 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()`](https://nodejs.org/docs/latest-v22.x/api/util.html#utilformatformat-args) for more information.

log
(
var e: any
e
.
any
message
) // please enter an integer
34
}
35
36
try {
37
const decode: (u: unknown, overrideOptions?: ParseOptions) => number
decode
("not a number")
38
} catch (
var e: any
e
: any) {
39
namespace console 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`](https://nodejs.org/docs/latest-v22.x/api/process.html#processstdout) and [`process.stderr`](https://nodejs.org/docs/latest-v22.x/api/process.html#processstderr). 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`](https://nodejs.org/docs/latest-v22.x/api/process.html#a-note-on-process-io) for more information. Example using the global `console`: ```js 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: ```js 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 ```

console
.
(method) 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)`](http://man7.org/linux/man-pages/man3/printf.3.html) (the arguments are all passed to [`util.format()`](https://nodejs.org/docs/latest-v22.x/api/util.html#utilformatformat-args)). ```js 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()`](https://nodejs.org/docs/latest-v22.x/api/util.html#utilformatformat-args) for more information.

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

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

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

Pipes the value of an expression into a pipeline of functions. This is useful in combination with data-last functions as a simulation of methods: ``` as.map(f).filter(g) -> pipe(as, map(f), filter(g)) ```

pipe
} from "effect"
3
4
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) namespace Struct
Struct
({
5
(property) outcomes: Schema.filter<Schema.Schema<readonly { readonly id: string; readonly text: string; }[], readonly { readonly id: string; readonly text: string; }[], never>>
outcomes
:
(alias) 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) import pipe

Pipes the value of an expression into a pipeline of functions. This is useful in combination with data-last functions as a simulation of methods: ``` as.map(f).filter(g) -> pipe(as, map(f), filter(g)) ```

pipe
(
6
import Schema
Schema
.
(alias) 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
Array
(
7
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) namespace Struct
Struct
({
8
(property) id: typeof Schema.String
id
:
import Schema
Schema
.
(alias) class String export String
String
,
9
(property) text: Schema.filter<Schema.Schema<string, string, never>>
text
:
(alias) 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) import pipe

Pipes the value of an expression into a pipeline of functions. This is useful in combination with data-last functions as a simulation of methods: ``` as.map(f).filter(g) -> pipe(as, map(f), filter(g)) ```

pipe
(
10
import Schema
Schema
.
(alias) class String export String
String
.
(method) Annotable<SchemaClass<string, string, never>, string, string, never>.annotations(annotations: Schema.Annotations.Schema<string, readonly []>): Schema.SchemaClass<string, string, never>

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

annotations
({
11
(property) Annotations.Schema<A, TypeParameters extends ReadonlyArray<any> = readonly []>.message?: MessageAnnotation
message
: () => "error_invalid_outcome_type"
12
}),
13
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<...>
minLength
(1, {
(property) Annotations.Schema<A, TypeParameters extends ReadonlyArray<any> = readonly []>.message?: MessageAnnotation
message
: () => "error_required_field" }),
14
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<...>
maxLength
(50, {
15
(property) Annotations.Schema<A, TypeParameters extends ReadonlyArray<any> = readonly []>.message?: MessageAnnotation
message
: () => "error_max_length_field"
16
})
17
)
18
})
19
),
20
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<...>
minItems
(1, {
(property) Annotations.Schema<A, TypeParameters extends ReadonlyArray<any> = readonly []>.message?: MessageAnnotation
message
: () => "error_min_length_field" })
21
)
22
})
23
24
import Schema
Schema
.
(alias) 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; }[]; }, { ...; }, never>, options?: ParseOptions): (u: unknown, overrideOptions?: ParseOptions) => { readonly outcomes: readonly { readonly id: string; readonly text: string; }[]; } export decodeUnknownSync
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
, {
(property) 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"

errors
: "all" })({
25
(property) outcomes: never[]
outcomes
: []
26
})
27
/*
28
throws
29
ParseError: { readonly outcomes: an array of at least 1 items }
30
└─ ["outcomes"]
31
└─ error_min_length_field
32
*/
33
34
import Schema
Schema
.
(alias) 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; }[]; }, { ...; }, never>, options?: ParseOptions): (u: unknown, overrideOptions?: ParseOptions) => { readonly outcomes: readonly { readonly id: string; readonly text: string; }[]; } export decodeUnknownSync
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
, {
(property) 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"

errors
: "all" })({
35
(property) outcomes: { id: string; text: string; }[]
outcomes
: [
36
{
(property) id: string
id
: "1",
(property) text: string
text
: "" },
37
{
(property) id: string
id
: "2",
(property) text: string
text
: "this one is valid" },
38
{
(property) id: string
id
: "3",
(property) text: string
text
: "1234567890".
(method) 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.

repeat
(6) }
39
]
40
})
41
/*
42
throws
43
ParseError: { readonly outcomes: an array of at least 1 items }
44
└─ ["outcomes"]
45
└─ an array of at least 1 items
46
└─ From side refinement failure
47
└─ ReadonlyArray<{ readonly id: string; readonly text: a string at most 50 character(s) long }>
48
├─ [0]
49
│ └─ { readonly id: string; readonly text: a string at most 50 character(s) long }
50
│ └─ ["text"]
51
│ └─ error_required_field
52
└─ [2]
53
└─ { readonly id: string; readonly text: a string at most 50 character(s) long }
54
└─ ["text"]
55
└─ error_max_length_field
56
*/

Messages are not only of type string but can return an Effect so that they can have dependencies (for example, from an internationalization service). Let’s see the outline of a similar situation with a very simplified example for demonstration purposes:

Example

1
import {
2
import Context
Context
,
3
import Effect
Effect
,
4
import Either
Either
,
5
import Option
Option
,
6
import Schema
Schema
,
7
import ParseResult
ParseResult
8
} from "effect"
9
10
// internationalization service
11
class
class Messages
Messages
extends
import Context
Context
.
const Tag: <"Messages">(id: "Messages") => <Self, Shape>() => Context.TagClass<Self, "Messages", Shape> namespace Tag
Tag
("Messages")<
12
class Messages
Messages
,
13
{
14
(property) NonEmpty: string
NonEmpty
: string
15
}
16
>() {}
17
18
const
const Name: Schema.refine<string, Schema.Schema<string, string, never>>
Name
=
import Schema
Schema
.
class NonEmptyString
NonEmptyString
.
(method) Annotable<refine<string, Schema<string, string, never>>, string, string, never>.annotations(annotations: Schema.Annotations.Schema<string, readonly []>): Schema.refine<string, Schema.Schema<string, string, never>>

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

annotations
({
19
(property) Annotations.Schema<string, readonly []>.message?: MessageAnnotation
message
: () =>
20
import Effect
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)
gen
(function* (
(parameter) _: Effect.Adapter
_
) {
21
const
const service: Option.Option<{ NonEmpty: string; }>
service
= yield*
(parameter) _: 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
Effect
.
const serviceOption: <Messages, { NonEmpty: string; }>(tag: Context.Tag<Messages, { NonEmpty: string; }>) => Effect.Effect<Option.Option<{ NonEmpty: string; }>, never, never>
serviceOption
(
class Messages
Messages
))
22
return
import Option
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.

match
(
const service: Option.Option<{ NonEmpty: string; }>
service
, {
23
(property) onNone: LazyArg<string>
onNone
: () => "Invalid string",
24
(property) onSome: (a: { NonEmpty: string; }) => string
onSome
: (
(parameter) messages: { NonEmpty: string; }
messages
) =>
(parameter) messages: { NonEmpty: string; }
messages
.
(property) NonEmpty: string
NonEmpty
25
})
26
})
27
})
28
29
import Schema
Schema
.
(alias) decodeUnknownSync<string, string>(schema: Schema.Schema<string, string, never>, options?: ParseOptions): (u: unknown, overrideOptions?: ParseOptions) => string export decodeUnknownSync
decodeUnknownSync
(
const Name: Schema.refine<string, Schema.Schema<string, string, never>>
Name
)("")
30
/*
31
throws:
32
ParseError: Invalid string
33
*/
34
35
const
const result: Either.Either<string, string>
result
=
import Schema
Schema
.
const decodeUnknownEither: <string, string>(schema: Schema.Schema<string, string, never>, options?: ParseOptions) => (u: unknown, overrideOptions?: ParseOptions) => Either.Either<...>
decodeUnknownEither
(
const Name: Schema.refine<string, Schema.Schema<string, string, never>>
Name
)("").
(method) Pipeable.pipe<Either.Either<string, ParseResult.ParseError>, Either.Either<string, string>>(this: Either.Either<...>, ab: (_: Either.Either<string, ParseResult.ParseError>) => Either.Either<...>): Either.Either<...> (+21 overloads)
pipe
(
36
import Either
Either
.
const mapLeft: <ParseResult.ParseError, string>(f: (left: ParseResult.ParseError) => string) => <R>(self: Either.Either<R, ParseResult.ParseError>) => Either.Either<...> (+1 overload)

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

mapLeft
((
(parameter) error: ParseResult.ParseError
error
) =>
37
import ParseResult
ParseResult
.
const TreeFormatter: ParseResult.ParseResultFormatter<string>
TreeFormatter
.
(property) ParseResultFormatter<string>.formatError: (error: ParseResult.ParseError) => Effect.Effect<string, never, never>
formatError
(
(parameter) error: ParseResult.ParseError
error
).
(method) Pipeable.pipe<Effect.Effect<string, never, never>, Effect.Effect<string, never, never>, string>(this: Effect.Effect<...>, ab: (_: Effect.Effect<string, never, never>) => Effect.Effect<string, never, never>, bc: (_: Effect.Effect<...>) => string): string (+21 overloads)
pipe
(
38
import Effect
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)

Provides the effect with the single service it requires. If the effect requires more than one service use `provide` instead.

provideService
(
class Messages
Messages
, {
39
(property) NonEmpty: string
NonEmpty
: "should be non empty"
40
}),
41
import Effect
Effect
.
const runSync: <A, E>(effect: Effect.Effect<A, E>) => A

Executes an effect synchronously and returns its result. Use `runSync` when you are certain that the effect is purely synchronous and will not perform any asynchronous operations. If the effect fails or contains asynchronous tasks, it will throw an error.

runSync
42
)
43
)
44
)
45
46
namespace console 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`](https://nodejs.org/docs/latest-v22.x/api/process.html#processstdout) and [`process.stderr`](https://nodejs.org/docs/latest-v22.x/api/process.html#processstderr). 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`](https://nodejs.org/docs/latest-v22.x/api/process.html#a-note-on-process-io) for more information. Example using the global `console`: ```js 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: ```js 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 ```

console
.
(method) 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)`](http://man7.org/linux/man-pages/man3/printf.3.html) (the arguments are all passed to [`util.format()`](https://nodejs.org/docs/latest-v22.x/api/util.html#utilformatformat-args)). ```js 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()`](https://nodejs.org/docs/latest-v22.x/api/util.html#utilformatformat-args) for more information.

log
(
const result: Either.Either<string, string>
result
)
47
/*
48
Output:
49
{ _id: 'Either', _tag: 'Left', left: 'should be non empty' }
50
*/

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

Example (Missing property)

1
import {
import Schema
Schema
} from "effect"
2
3
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) namespace Struct
Struct
({
4
(property) 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`.

propertySignature
(
import Schema
Schema
.
(alias) class String export String
String
).
(method) 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
({
5
(property) 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"
6
})
7
})
8
9
import Schema
Schema
.
(alias) 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
decodeUnknownSync
(
const Person: Schema.Struct<{ name: Schema.propertySignature<typeof Schema.String>; }>
Person
)({})
10
/*
11
throws:
12
ParseError: { readonly name: string }
13
└─ ["name"]
14
└─ Name is required
15
*/

Example (Missing element)

1
import {
import Schema
Schema
} from "effect"
2
3
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)
Tuple
(
4
import Schema
Schema
.
const element: <typeof Schema.Number>(self: typeof Schema.Number) => Schema.Element<typeof Schema.Number, "">
element
(
import Schema
Schema
.
(alias) class Number export Number
Number
).
(method) 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
({
5
(property) 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"
6
}),
7
import Schema
Schema
.
const element: <typeof Schema.Number>(self: typeof Schema.Number) => Schema.Element<typeof Schema.Number, "">
element
(
import Schema
Schema
.
(alias) class Number export Number
Number
).
(method) 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
({
8
(property) 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"
9
})
10
)
11
12
import Schema
Schema
.
(alias) 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
decodeUnknownSync
(
const Point: Schema.Tuple<[Schema.Element<typeof Schema.Number, "">, Schema.Element<typeof Schema.Number, "">]>
Point
)([], {
(property) 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"

errors
: "all" })
13
/*
14
throws:
15
ParseError: readonly [number, number]
16
├─ [0]
17
│ └─ X coordinate is required
18
└─ [1]
19
└─ Y coordinate is required
20
*/