Skip to content

Default Constructors

When working with data structures, it can be helpful to create values that conform to a schema with minimal effort. For this purpose, the Schema module provides default constructors for various schema types, including Structs, Records, filters, and brands.

Struct schemas allow you to define objects with specific fields and constraints. The make function can be used to create instances of a struct schema.

Example (Creating Struct Instances)

1
import {
import Schema
Schema
} from "effect"
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 throw 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
*/

In some cases, you might need to bypass validation. While not recommended in most scenarios, make provides an option to disable validation.

Example (Bypassing Validation)

1
import {
import Schema
Schema
} from "effect"
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
// Bypass validation during instantiation
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
: "" }, true)
9
10
// Or use the `disableValidation` option explicitly
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
: "" }, {
(property) disableValidation?: boolean
disableValidation
: true })

Record schemas allow you to define key-value mappings where the keys and values must meet specific criteria.

Example (Creating Record Instances)

1
import {
import Schema
Schema
} from "effect"
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 throw 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 })

Filters allow you to define constraints on individual values.

Example (Using Filters to Enforce Ranges)

1
import {
import Schema
Schema
} from "effect"
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 throw 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 })

Branded schemas add metadata to a value to give it a more specific type, while still retaining its original type.

Example (Creating Branded Values)

1
import {
import Schema
Schema
} from "effect"
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 throw 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 using default constructors, it is helpful to understand the type of value they produce.

For instance, in the BrandedNumberSchema example, the return type of the constructor is number & Brand<"MyNumber">. This indicates that the resulting value is a number with additional branding information, "MyNumber".

This behavior contrasts with the filter example, where the return type is simply number. Branding adds an extra layer of type information, which can assist in identifying and working with your data more effectively.

Default constructors are considered “unsafe” because they throw an error if the input does not conform to the schema. This error includes a detailed description of what went wrong. The intention behind default constructors is to provide a straightforward way to create valid values, such as for tests or configurations, where invalid inputs are expected to be exceptional cases.

If you need a “safe” constructor that does not throw errors but instead returns a result indicating success or failure, you can use Schema.validateEither.

Example (Using Schema.validateEither for Safe Validation)

1
import {
import Schema
Schema
} from "effect"
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
// Create a safe constructor that validates the input
6
const
const makeMyNumber: (u: unknown, overrideOptions?: ParseOptions) => Either<number, ParseError>
makeMyNumber
=
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
)
7
8
// Valid input returns a Right value
9
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 makeMyNumber: (u: unknown, overrideOptions?: ParseOptions) => Either<number, ParseError>
makeMyNumber
(5))
10
/*
11
Output:
12
{ _id: 'Either', _tag: 'Right', right: 5 }
13
*/
14
15
// Invalid input returns a Left value with detailed error information
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
(
const makeMyNumber: (u: unknown, overrideOptions?: ParseOptions) => Either<number, ParseError>
makeMyNumber
(20))
17
/*
18
Output:
19
{
20
_id: 'Either',
21
_tag: 'Left',
22
left: {
23
_id: 'ParseError',
24
message: 'a number between 1 and 10\n' +
25
'└─ Predicate refinement failure\n' +
26
' └─ Expected a number between 1 and 10, actual 20'
27
}
28
}
29
*/

When creating objects, you might want to assign default values to certain fields to simplify object construction. The Schema.withConstructorDefault function lets you handle default values, making fields optional in the default constructor.

Example (Struct with Required Fields)

In this example, all fields are required when creating a new instance.

1
import {
import Schema
Schema
} from "effect"
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 must be provided
9
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: 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 }))
10
/*
11
Output: { name: 'John', age: 30 }
12
*/

Example (Struct with Default Value)

Here, the age field is optional because it has a default value of 0.

1
import {
import Schema
Schema
} from "effect"
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
{ name: 'John', age: 0 }
16
*/
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>; }>
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",
(property) age?: number
age
: 30 }))
19
/*
20
Output:
21
{ name: 'John', age: 30 }
22
*/

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

Example (Lazy Evaluation of Defaults)

In this example, the timestamp field generates a new value for each instance.

1
import {
import Schema
Schema
} from "effect"
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
/*
17
Example Output:
18
{ age: 0, timestamp: 1714232909221, name: 'name1' }
19
*/
20
21
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" }))
22
/*
23
Example Output:
24
{ age: 0, timestamp: 1714232909227, name: 'name2' }
25
*/

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

Example (Reusing Defaults in Another Schema)

1
import {
import Schema
Schema
} from "effect"
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" }))
21
/*
22
Output:
23
{ foo: 'bar', age: 0 }
24
*/

Default values can also be applied when working with the Class API, ensuring consistency across class-based schemas.

Example (Defaults in a Class)

1
import {
import Schema
Schema
} from "effect"
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
/*
17
Example Output:
18
Person { age: 0, timestamp: 1714400867208, name: 'name1' }
19
*/
20
21
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" }))
22
/*
23
Example Output:
24
Person { age: 0, timestamp: 1714400867215, name: 'name2' }
25
*/