Skip to content

Default Constructors

When working with data structures, it’s advantageous to be able to construct values that align with a specific schema effortlessly. For this purpose, we offer default constructors for several types of schemas, including Structs, Records, filters, and brands.

Example

1
import {
import Schema
Schema
} from "@effect/schema"
2
3
const
const Struct: Schema.Struct<{ name: typeof Schema.NonEmptyString; }>
Struct
=
import Schema
Schema
.
function Struct<{ name: typeof Schema.NonEmptyString; }>(fields: { name: typeof Schema.NonEmptyString; }): Schema.Struct<{ name: typeof Schema.NonEmptyString; }> (+1 overload) namespace Struct
Struct
({
4
(property) name: typeof Schema.NonEmptyString
name
:
import Schema
Schema
.
class NonEmptyString
NonEmptyString
5
})
6
7
// Successful creation
8
const Struct: Schema.Struct<{ name: typeof Schema.NonEmptyString; }>
Struct
.
(method) TypeLiteral<{ name: typeof NonEmptyString; }, []>.make(props: { readonly name: string; }, options?: MakeOptions): { readonly name: string; }
make
({
(property) name: string
name
: "a" })
9
10
// This will cause an error because the name is empty
11
const Struct: Schema.Struct<{ name: typeof Schema.NonEmptyString; }>
Struct
.
(method) TypeLiteral<{ name: typeof NonEmptyString; }, []>.make(props: { readonly name: string; }, options?: MakeOptions): { readonly name: string; }
make
({
(property) name: string
name
: "" })
12
/*
13
throws
14
ParseError: { readonly name: NonEmptyString }
15
└─ ["name"]
16
└─ NonEmptyString
17
└─ Predicate refinement failure
18
└─ Expected NonEmptyString, actual ""
19
*/

There are scenarios where you might want to bypass validation during instantiation. Although not typically recommended, @effect/schema allows for this flexibility:

1
import { Schema } from "@effect/schema"
2
3
const Struct = Schema.Struct({
4
name: Schema.NonEmptyString
5
const Struct: Schema.Struct<{ name: typeof Schema.NonEmptyString; }>
})
6
7
// ---cut---
8
// Bypasses validation, thus avoiding errors
9
Struct.make({ name: "" }, true)
10
11
// or more explicitly
12
Struct.make({ name: "" }, { disableValidation: true })

Example

1
import {
import Schema
Schema
} from "@effect/schema"
2
3
const
const Record: Schema.Record$<typeof Schema.String, typeof Schema.NonEmptyString>
Record
=
import Schema
Schema
.
const Record: <typeof Schema.String, typeof Schema.NonEmptyString>(options: { readonly key: typeof Schema.String; readonly value: typeof Schema.NonEmptyString; }) => Schema.Record$<typeof Schema.String, typeof Schema.NonEmptyString>
Record
({
4
(property) key: typeof Schema.String
key
:
import Schema
Schema
.
(alias) class String export String
String
,
5
(property) value: typeof Schema.NonEmptyString
value
:
import Schema
Schema
.
class NonEmptyString
NonEmptyString
6
})
7
8
// Successful creation
9
const Record: Schema.Record$<typeof Schema.String, typeof Schema.NonEmptyString>
Record
.
(method) TypeLiteral<{}, [{ key: typeof String$; value: typeof NonEmptyString; }]>.make(props: { readonly [x: string]: string; }, options?: MakeOptions): { readonly [x: string]: string; }
make
({
(property) a: string
a
: "a",
(property) b: string
b
: "b" })
10
11
// This will cause an error because 'b' is empty
12
const Record: Schema.Record$<typeof Schema.String, typeof Schema.NonEmptyString>
Record
.
(method) TypeLiteral<{}, [{ key: typeof String$; value: typeof NonEmptyString; }]>.make(props: { readonly [x: string]: string; }, options?: MakeOptions): { readonly [x: string]: string; }
make
({
(property) a: string
a
: "a",
(property) b: string
b
: "" })
13
/*
14
throws
15
ParseError: { readonly [x: string]: NonEmptyString }
16
└─ ["b"]
17
└─ NonEmptyString
18
└─ Predicate refinement failure
19
└─ Expected NonEmptyString, actual ""
20
*/
21
22
// Bypasses validation
23
const Record: Schema.Record$<typeof Schema.String, typeof Schema.NonEmptyString>
Record
.
(method) TypeLiteral<{}, [{ key: typeof String$; value: typeof NonEmptyString; }]>.make(props: { readonly [x: string]: string; }, options?: MakeOptions): { readonly [x: string]: string; }
make
({
(property) a: string
a
: "a",
(property) b: string
b
: "" }, {
(property) disableValidation?: boolean
disableValidation
: true })

Example

1
import {
import Schema
Schema
} from "@effect/schema"
2
3
const
const MyNumber: Schema.filter<Schema.Schema<number, number, never>>
MyNumber
=
import Schema
Schema
.
(alias) class Number export Number
Number
.
(method) Pipeable.pipe<typeof Schema.Number, Schema.filter<Schema.Schema<number, number, never>>>(this: typeof Schema.Number, ab: (_: typeof Schema.Number) => Schema.filter<Schema.Schema<number, number, never>>): Schema.filter<...> (+21 overloads)
pipe
(
import Schema
Schema
.
const between: <number>(min: number, max: number, annotations?: Schema.Annotations.Filter<number, number> | undefined) => <I, R>(self: Schema.Schema<number, I, R>) => Schema.filter<...>

This filter checks whether the provided number falls within the specified minimum and maximum values.

between
(1, 10))
4
5
// Successful creation
6
const
const n: number
n
=
const MyNumber: Schema.filter<Schema.Schema<number, number, never>>
MyNumber
.
(method) refine<number, Schema<number, number, never>>.make(a: number, options?: MakeOptions): number
make
(5)
7
8
// This will cause an error because the number is outside the valid range
9
const MyNumber: Schema.filter<Schema.Schema<number, number, never>>
MyNumber
.
(method) refine<number, Schema<number, number, never>>.make(a: number, options?: MakeOptions): number
make
(20)
10
/*
11
throws
12
ParseError: a number between 1 and 10
13
└─ Predicate refinement failure
14
└─ Expected a number between 1 and 10, actual 20
15
*/
16
17
// Bypasses validation
18
const MyNumber: Schema.filter<Schema.Schema<number, number, never>>
MyNumber
.
(method) refine<number, Schema<number, number, never>>.make(a: number, options?: MakeOptions): number
make
(20, {
(property) disableValidation?: boolean
disableValidation
: true })

Example

1
import {
import Schema
Schema
} from "@effect/schema"
2
3
const
const BrandedNumberSchema: Schema.brand<Schema.filter<Schema.Schema<number, number, never>>, "MyNumber">
BrandedNumberSchema
=
import Schema
Schema
.
(alias) class Number export Number
Number
.
(method) Pipeable.pipe<typeof Schema.Number, Schema.filter<Schema.Schema<number, number, never>>, Schema.brand<Schema.filter<Schema.Schema<number, number, never>>, "MyNumber">>(this: typeof Schema.Number, ab: (_: typeof Schema.Number) => Schema.filter<...>, bc: (_: Schema.filter<...>) => Schema.brand<...>): Schema.brand<...> (+21 overloads)
pipe
(
4
import Schema
Schema
.
const between: <number>(min: number, max: number, annotations?: Schema.Annotations.Filter<number, number> | undefined) => <I, R>(self: Schema.Schema<number, I, R>) => Schema.filter<...>

This filter checks whether the provided number falls within the specified minimum and maximum values.

between
(1, 10),
5
import Schema
Schema
.
const brand: <Schema.filter<Schema.Schema<number, number, never>>, "MyNumber">(brand: "MyNumber", annotations?: Schema.Annotations.Schema<number & Brand<"MyNumber">, readonly []> | undefined) => (self: Schema.filter<...>) => Schema.brand<...>

Returns a nominal branded schema by applying a brand to a given schema. ``` Schema<A> + B -> Schema<A & Brand<B>> ```

brand
("MyNumber")
6
)
7
8
// Successful creation
9
const
const n: number & Brand<"MyNumber">
n
=
const BrandedNumberSchema: Schema.brand<Schema.filter<Schema.Schema<number, number, never>>, "MyNumber">
BrandedNumberSchema
.
(method) BrandSchema<number & Brand<"MyNumber">, number, never>.make(a: number, options?: MakeOptions): number & Brand<"MyNumber">
make
(5)
10
11
// This will cause an error because the number is outside the valid range
12
const BrandedNumberSchema: Schema.brand<Schema.filter<Schema.Schema<number, number, never>>, "MyNumber">
BrandedNumberSchema
.
(method) BrandSchema<number & Brand<"MyNumber">, number, never>.make(a: number, options?: MakeOptions): number & Brand<"MyNumber">
make
(20)
13
/*
14
throws
15
ParseError: a number between 1 and 10 & Brand<"MyNumber">
16
└─ Predicate refinement failure
17
└─ Expected a number between 1 and 10 & Brand<"MyNumber">, actual 20
18
*/
19
20
// Bypasses validation
21
const BrandedNumberSchema: Schema.brand<Schema.filter<Schema.Schema<number, number, never>>, "MyNumber">
BrandedNumberSchema
.
(method) BrandSchema<number & Brand<"MyNumber">, number, never>.make(a: number, options?: MakeOptions): number & Brand<"MyNumber">
make
(20, {
(property) disableValidation?: boolean
disableValidation
: true })

When utilizing our default constructors, it’s important to grasp the type of value they generate. In the BrandedNumberSchema example, the return type of the constructor is number & Brand<"MyNumber">, indicating that the resulting value is a number with the added branding “MyNumber”.

This differs from the filter example where the return type is simply number. The branding offers additional insights about the type, facilitating the identification and manipulation of your data.

Note that default constructors are “unsafe” in the sense that if the input does not conform to the schema, the constructor throws an error containing a description of what is wrong. This is because the goal of default constructors is to provide a quick way to create compliant values (for example, for writing tests or configurations, or in any situation where it is assumed that the input passed to the constructors is valid and the opposite situation is exceptional). To have a “safe” constructor, you can use Schema.validateEither:

1
import {
import Schema
Schema
} from "@effect/schema"
2
3
const
const MyNumber: Schema.filter<Schema.Schema<number, number, never>>
MyNumber
=
import Schema
Schema
.
(alias) class Number export Number
Number
.
(method) Pipeable.pipe<typeof Schema.Number, Schema.filter<Schema.Schema<number, number, never>>>(this: typeof Schema.Number, ab: (_: typeof Schema.Number) => Schema.filter<Schema.Schema<number, number, never>>): Schema.filter<...> (+21 overloads)
pipe
(
import Schema
Schema
.
const between: <number>(min: number, max: number, annotations?: Schema.Annotations.Filter<number, number> | undefined) => <I, R>(self: Schema.Schema<number, I, R>) => Schema.filter<...>

This filter checks whether the provided number falls within the specified minimum and maximum values.

between
(1, 10))
4
5
const
const ctor: (u: unknown, overrideOptions?: ParseOptions) => Either<number, ParseError>
ctor
=
import Schema
Schema
.
const validateEither: <number, number, never>(schema: Schema.Schema<number, number, never>, options?: ParseOptions) => (u: unknown, overrideOptions?: ParseOptions) => Either<...>
validateEither
(
const MyNumber: Schema.filter<Schema.Schema<number, number, never>>
MyNumber
)
6
7
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 ctor: (u: unknown, overrideOptions?: ParseOptions) => Either<number, ParseError>
ctor
(5))
8
/*
9
{ _id: 'Either', _tag: 'Right', right: 5 }
10
*/
11
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
(
const ctor: (u: unknown, overrideOptions?: ParseOptions) => Either<number, ParseError>
ctor
(20))
13
/*
14
{
15
_id: 'Either',
16
_tag: 'Left',
17
left: {
18
_id: 'ParseError',
19
message: 'a number between 1 and 10\n' +
20
'└─ Predicate refinement failure\n' +
21
' └─ Expected a number between 1 and 10, actual 20'
22
}
23
}
24
*/

When constructing objects, it’s common to want to assign default values to certain fields to simplify the creation of new instances. The Schema.withConstructorDefault function allows you to manage the optionality of a field in your default constructor.

Example (Without Default)

1
import {
import Schema
Schema
} from "@effect/schema"
2
3
const
const Person: Schema.Struct<{ name: typeof Schema.NonEmptyString; age: typeof Schema.Number; }>
Person
=
import Schema
Schema
.
function Struct<{ name: typeof Schema.NonEmptyString; age: typeof Schema.Number; }>(fields: { name: typeof Schema.NonEmptyString; age: typeof Schema.Number; }): Schema.Struct<{ name: typeof Schema.NonEmptyString; age: typeof Schema.Number; }> (+1 overload) namespace Struct
Struct
({
4
(property) name: typeof Schema.NonEmptyString
name
:
import Schema
Schema
.
class NonEmptyString
NonEmptyString
,
5
(property) age: typeof Schema.Number
age
:
import Schema
Schema
.
(alias) class Number export Number
Number
6
})
7
8
// Both name and age are required
9
const Person: Schema.Struct<{ name: typeof Schema.NonEmptyString; age: typeof Schema.Number; }>
Person
.
(method) TypeLiteral<{ name: typeof NonEmptyString; age: typeof Number$; }, []>.make(props: { readonly name: string; readonly age: number; }, options?: MakeOptions): { readonly name: string; readonly age: number; }
make
({
(property) name: string
name
: "John",
(property) age: number
age
: 30 })

Example (With Default)

1
import {
import Schema
Schema
} from "@effect/schema"
2
3
const
const Person: Schema.Struct<{ name: typeof Schema.NonEmptyString; age: Schema.PropertySignature<":", number, never, ":", number, true, never>; }>
Person
=
import Schema
Schema
.
function Struct<{ name: typeof Schema.NonEmptyString; age: Schema.PropertySignature<":", number, never, ":", number, true, never>; }>(fields: { name: typeof Schema.NonEmptyString; age: Schema.PropertySignature<":", ... 5 more ..., never>; }): Schema.Struct<...> (+1 overload) namespace Struct
Struct
({
4
(property) name: typeof Schema.NonEmptyString
name
:
import Schema
Schema
.
class NonEmptyString
NonEmptyString
,
5
(property) age: Schema.PropertySignature<":", number, never, ":", number, true, never>
age
:
import Schema
Schema
.
(alias) class Number export Number
Number
.
(method) Pipeable.pipe<typeof Schema.Number, Schema.propertySignature<typeof Schema.Number>, Schema.PropertySignature<":", number, never, ":", number, true, never>>(this: typeof Schema.Number, ab: (_: typeof Schema.Number) => Schema.propertySignature<...>, bc: (_: Schema.propertySignature<...>) => Schema.PropertySignature<...>): Schema.PropertySignature<...> (+21 overloads)
pipe
(
6
import Schema
Schema
.
const propertySignature: <S extends Schema.Schema.All>(self: S) => Schema.propertySignature<S>

Lifts a `Schema` into a `PropertySignature`.

propertySignature
,
7
import Schema
Schema
.
const withConstructorDefault: <number>(defaultValue: () => number) => <TypeToken, Key, EncodedToken, Encoded, R>(self: Schema.PropertySignature<TypeToken, number, Key, EncodedToken, Encoded, boolean, R>) => Schema.PropertySignature<...> (+1 overload)

Enhances a property signature with a default constructor value.

withConstructorDefault
(() => 0)
8
)
9
})
10
11
// The age field is optional and defaults to 0
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
(
const Person: Schema.Struct<{ name: typeof Schema.NonEmptyString; age: Schema.PropertySignature<":", number, never, ":", number, true, never>; }>
Person
.
(method) TypeLiteral<{ name: typeof NonEmptyString; age: PropertySignature<":", number, never, ":", number, true, never>; }, []>.make(props: { readonly name: string; readonly age?: number; }, options?: MakeOptions): { readonly name: string; readonly age: number; }
make
({
(property) name: string
name
: "John" }))
13
/*
14
Output:
15
{ age: 0, name: 'John' }
16
*/

In the second example, notice how the age field is now optional and defaults to 0 when not provided.

Defaults are lazily evaluated, meaning that a new instance of the default is generated every time the constructor is called:

1
import {
import Schema
Schema
} from "@effect/schema"
2
3
const
const Person: Schema.Struct<{ name: typeof Schema.NonEmptyString; age: Schema.PropertySignature<":", number, never, ":", number, true, never>; timestamp: Schema.PropertySignature<":", number, never, ":", number, true, never>; }>
Person
=
import Schema
Schema
.
function Struct<{ name: typeof Schema.NonEmptyString; age: Schema.PropertySignature<":", number, never, ":", number, true, never>; timestamp: Schema.PropertySignature<":", number, never, ":", number, true, never>; }>(fields: { ...; }): Schema.Struct<...> (+1 overload) namespace Struct
Struct
({
4
(property) name: typeof Schema.NonEmptyString
name
:
import Schema
Schema
.
class NonEmptyString
NonEmptyString
,
5
(property) age: Schema.PropertySignature<":", number, never, ":", number, true, never>
age
:
import Schema
Schema
.
(alias) class Number export Number
Number
.
(method) Pipeable.pipe<typeof Schema.Number, Schema.propertySignature<typeof Schema.Number>, Schema.PropertySignature<":", number, never, ":", number, true, never>>(this: typeof Schema.Number, ab: (_: typeof Schema.Number) => Schema.propertySignature<...>, bc: (_: Schema.propertySignature<...>) => Schema.PropertySignature<...>): Schema.PropertySignature<...> (+21 overloads)
pipe
(
6
import Schema
Schema
.
const propertySignature: <S extends Schema.Schema.All>(self: S) => Schema.propertySignature<S>

Lifts a `Schema` into a `PropertySignature`.

propertySignature
,
7
import Schema
Schema
.
const withConstructorDefault: <number>(defaultValue: () => number) => <TypeToken, Key, EncodedToken, Encoded, R>(self: Schema.PropertySignature<TypeToken, number, Key, EncodedToken, Encoded, boolean, R>) => Schema.PropertySignature<...> (+1 overload)

Enhances a property signature with a default constructor value.

withConstructorDefault
(() => 0)
8
),
9
(property) timestamp: Schema.PropertySignature<":", number, never, ":", number, true, never>
timestamp
:
import Schema
Schema
.
(alias) class Number export Number
Number
.
(method) Pipeable.pipe<typeof Schema.Number, Schema.propertySignature<typeof Schema.Number>, Schema.PropertySignature<":", number, never, ":", number, true, never>>(this: typeof Schema.Number, ab: (_: typeof Schema.Number) => Schema.propertySignature<...>, bc: (_: Schema.propertySignature<...>) => Schema.PropertySignature<...>): Schema.PropertySignature<...> (+21 overloads)
pipe
(
10
import Schema
Schema
.
const propertySignature: <S extends Schema.Schema.All>(self: S) => Schema.propertySignature<S>

Lifts a `Schema` into a `PropertySignature`.

propertySignature
,
11
import Schema
Schema
.
const withConstructorDefault: <number>(defaultValue: () => number) => <TypeToken, Key, EncodedToken, Encoded, R>(self: Schema.PropertySignature<TypeToken, number, Key, EncodedToken, Encoded, boolean, R>) => Schema.PropertySignature<...> (+1 overload)

Enhances a property signature with a default constructor value.

withConstructorDefault
(() => new
var Date: DateConstructor new () => Date (+3 overloads)
Date
().
(method) Date.getTime(): number

Returns the stored time value in milliseconds since midnight, January 1, 1970 UTC.

getTime
())
12
)
13
})
14
15
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 Person: Schema.Struct<{ name: typeof Schema.NonEmptyString; age: Schema.PropertySignature<":", number, never, ":", number, true, never>; timestamp: Schema.PropertySignature<":", number, never, ":", number, true, never>; }>
Person
.
(method) TypeLiteral<{ name: typeof NonEmptyString; age: PropertySignature<":", number, never, ":", number, true, never>; timestamp: PropertySignature<":", number, never, ":", number, true, never>; }, []>.make(props: { readonly name: string; readonly age?: number; readonly timestamp?: number; }, options?: MakeOptions): { readonly name: string; readonly age: number; readonly timestamp: number; }
make
({
(property) name: string
name
: "name1" }))
16
// { age: 0, timestamp: 1714232909221, name: 'name1' }
17
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
(
const Person: Schema.Struct<{ name: typeof Schema.NonEmptyString; age: Schema.PropertySignature<":", number, never, ":", number, true, never>; timestamp: Schema.PropertySignature<":", number, never, ":", number, true, never>; }>
Person
.
(method) TypeLiteral<{ name: typeof NonEmptyString; age: PropertySignature<":", number, never, ":", number, true, never>; timestamp: PropertySignature<":", number, never, ":", number, true, never>; }, []>.make(props: { readonly name: string; readonly age?: number; readonly timestamp?: number; }, options?: MakeOptions): { readonly name: string; readonly age: number; readonly timestamp: number; }
make
({
(property) name: string
name
: "name2" }))
19
// { age: 0, timestamp: 1714232909227, name: 'name2' }

Note how the timestamp field varies.

Default values are also “portable”, meaning that if you reuse the same property signature in another schema, the default is carried over:

1
import {
import Schema
Schema
} from "@effect/schema"
2
3
const
const Person: Schema.Struct<{ name: typeof Schema.NonEmptyString; age: Schema.PropertySignature<":", number, never, ":", number, true, never>; timestamp: Schema.PropertySignature<":", number, never, ":", number, true, never>; }>
Person
=
import Schema
Schema
.
function Struct<{ name: typeof Schema.NonEmptyString; age: Schema.PropertySignature<":", number, never, ":", number, true, never>; timestamp: Schema.PropertySignature<":", number, never, ":", number, true, never>; }>(fields: { ...; }): Schema.Struct<...> (+1 overload) namespace Struct
Struct
({
4
(property) name: typeof Schema.NonEmptyString
name
:
import Schema
Schema
.
class NonEmptyString
NonEmptyString
,
5
(property) age: Schema.PropertySignature<":", number, never, ":", number, true, never>
age
:
import Schema
Schema
.
(alias) class Number export Number
Number
.
(method) Pipeable.pipe<typeof Schema.Number, Schema.propertySignature<typeof Schema.Number>, Schema.PropertySignature<":", number, never, ":", number, true, never>>(this: typeof Schema.Number, ab: (_: typeof Schema.Number) => Schema.propertySignature<...>, bc: (_: Schema.propertySignature<...>) => Schema.PropertySignature<...>): Schema.PropertySignature<...> (+21 overloads)
pipe
(
6
import Schema
Schema
.
const propertySignature: <S extends Schema.Schema.All>(self: S) => Schema.propertySignature<S>

Lifts a `Schema` into a `PropertySignature`.

propertySignature
,
7
import Schema
Schema
.
const withConstructorDefault: <number>(defaultValue: () => number) => <TypeToken, Key, EncodedToken, Encoded, R>(self: Schema.PropertySignature<TypeToken, number, Key, EncodedToken, Encoded, boolean, R>) => Schema.PropertySignature<...> (+1 overload)

Enhances a property signature with a default constructor value.

withConstructorDefault
(() => 0)
8
),
9
(property) timestamp: Schema.PropertySignature<":", number, never, ":", number, true, never>
timestamp
:
import Schema
Schema
.
(alias) class Number export Number
Number
.
(method) Pipeable.pipe<typeof Schema.Number, Schema.propertySignature<typeof Schema.Number>, Schema.PropertySignature<":", number, never, ":", number, true, never>>(this: typeof Schema.Number, ab: (_: typeof Schema.Number) => Schema.propertySignature<...>, bc: (_: Schema.propertySignature<...>) => Schema.PropertySignature<...>): Schema.PropertySignature<...> (+21 overloads)
pipe
(
10
import Schema
Schema
.
const propertySignature: <S extends Schema.Schema.All>(self: S) => Schema.propertySignature<S>

Lifts a `Schema` into a `PropertySignature`.

propertySignature
,
11
import Schema
Schema
.
const withConstructorDefault: <number>(defaultValue: () => number) => <TypeToken, Key, EncodedToken, Encoded, R>(self: Schema.PropertySignature<TypeToken, number, Key, EncodedToken, Encoded, boolean, R>) => Schema.PropertySignature<...> (+1 overload)

Enhances a property signature with a default constructor value.

withConstructorDefault
(() => new
var Date: DateConstructor new () => Date (+3 overloads)
Date
().
(method) Date.getTime(): number

Returns the stored time value in milliseconds since midnight, January 1, 1970 UTC.

getTime
())
12
)
13
})
14
15
const
const AnotherSchema: Schema.Struct<{ foo: typeof Schema.String; age: Schema.PropertySignature<":", number, never, ":", number, true, never>; }>
AnotherSchema
=
import Schema
Schema
.
function Struct<{ foo: typeof Schema.String; age: Schema.PropertySignature<":", number, never, ":", number, true, never>; }>(fields: { foo: typeof Schema.String; age: Schema.PropertySignature<":", number, never, ":", number, true, never>; }): Schema.Struct<...> (+1 overload) namespace Struct
Struct
({
16
(property) foo: typeof Schema.String
foo
:
import Schema
Schema
.
(alias) class String export String
String
,
17
(property) age: Schema.PropertySignature<":", number, never, ":", number, true, never>
age
:
const Person: Schema.Struct<{ name: typeof Schema.NonEmptyString; age: Schema.PropertySignature<":", number, never, ":", number, true, never>; timestamp: Schema.PropertySignature<":", number, never, ":", number, true, never>; }>
Person
.
(property) TypeLiteral<{ name: typeof NonEmptyString; age: PropertySignature<":", number, never, ":", number, true, never>; timestamp: PropertySignature<":", number, never, ":", number, true, never>; }, []>.fields: { readonly name: typeof Schema.NonEmptyString; readonly age: Schema.PropertySignature<":", number, never, ":", number, true, never>; readonly timestamp: Schema.PropertySignature<":", number, never, ":", number, true, never>; }
fields
.
(property) age: Schema.PropertySignature<":", number, never, ":", number, true, never>
age
18
})
19
20
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 AnotherSchema: Schema.Struct<{ foo: typeof Schema.String; age: Schema.PropertySignature<":", number, never, ":", number, true, never>; }>
AnotherSchema
.
(method) TypeLiteral<{ foo: typeof String$; age: PropertySignature<":", number, never, ":", number, true, never>; }, []>.make(props: { readonly age?: number; readonly foo: string; }, options?: MakeOptions): { readonly age: number; readonly foo: string; }
make
({
(property) foo: string
foo
: "bar" })) // => { foo: 'bar', age: 0 }

Defaults can also be applied using the Class API:

1
import {
import Schema
Schema
} from "@effect/schema"
2
3
class
class Person
Person
extends
import Schema
Schema
.
const Class: <Person>(identifier: string) => <Fields>(fieldsOr: Fields | HasFields<Fields>, annotations?: Schema.Annotations.Schema<Person, readonly []> | undefined) => Schema.Class<...>
Class
<
class Person
Person
>("Person")({
4
(property) name: typeof Schema.NonEmptyString
name
:
import Schema
Schema
.
class NonEmptyString
NonEmptyString
,
5
(property) age: Schema.PropertySignature<":", number, never, ":", number, true, never>
age
:
import Schema
Schema
.
(alias) class Number export Number
Number
.
(method) Pipeable.pipe<typeof Schema.Number, Schema.propertySignature<typeof Schema.Number>, Schema.PropertySignature<":", number, never, ":", number, true, never>>(this: typeof Schema.Number, ab: (_: typeof Schema.Number) => Schema.propertySignature<...>, bc: (_: Schema.propertySignature<...>) => Schema.PropertySignature<...>): Schema.PropertySignature<...> (+21 overloads)
pipe
(
6
import Schema
Schema
.
const propertySignature: <S extends Schema.Schema.All>(self: S) => Schema.propertySignature<S>

Lifts a `Schema` into a `PropertySignature`.

propertySignature
,
7
import Schema
Schema
.
const withConstructorDefault: <number>(defaultValue: () => number) => <TypeToken, Key, EncodedToken, Encoded, R>(self: Schema.PropertySignature<TypeToken, number, Key, EncodedToken, Encoded, boolean, R>) => Schema.PropertySignature<...> (+1 overload)

Enhances a property signature with a default constructor value.

withConstructorDefault
(() => 0)
8
),
9
(property) timestamp: Schema.PropertySignature<":", number, never, ":", number, true, never>
timestamp
:
import Schema
Schema
.
(alias) class Number export Number
Number
.
(method) Pipeable.pipe<typeof Schema.Number, Schema.propertySignature<typeof Schema.Number>, Schema.PropertySignature<":", number, never, ":", number, true, never>>(this: typeof Schema.Number, ab: (_: typeof Schema.Number) => Schema.propertySignature<...>, bc: (_: Schema.propertySignature<...>) => Schema.PropertySignature<...>): Schema.PropertySignature<...> (+21 overloads)
pipe
(
10
import Schema
Schema
.
const propertySignature: <S extends Schema.Schema.All>(self: S) => Schema.propertySignature<S>

Lifts a `Schema` into a `PropertySignature`.

propertySignature
,
11
import Schema
Schema
.
const withConstructorDefault: <number>(defaultValue: () => number) => <TypeToken, Key, EncodedToken, Encoded, R>(self: Schema.PropertySignature<TypeToken, number, Key, EncodedToken, Encoded, boolean, R>) => Schema.PropertySignature<...> (+1 overload)

Enhances a property signature with a default constructor value.

withConstructorDefault
(() => new
var Date: DateConstructor new () => Date (+3 overloads)
Date
().
(method) Date.getTime(): number

Returns the stored time value in milliseconds since midnight, January 1, 1970 UTC.

getTime
())
12
)
13
}) {}
14
15
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
(new
constructor Person(props: { readonly name: string; readonly age?: number; readonly timestamp?: number; }, options?: MakeOptions): Person
Person
({
(property) name: string
name
: "name1" }))
16
// Person { age: 0, timestamp: 1714400867208, name: 'name1' }
17
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
(new
constructor Person(props: { readonly name: string; readonly age?: number; readonly timestamp?: number; }, options?: MakeOptions): Person
Person
({
(property) name: string
name
: "name2" }))
19
// Person { age: 0, timestamp: 1714400867215, name: 'name2' }