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)

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

@since3.10.0

Struct
({
name: typeof Schema.NonEmptyString
name
:
import Schema
Schema
.
class NonEmptyString

@since3.10.0

NonEmptyString
})
// Successful creation
const Struct: Schema.Struct<{
name: typeof Schema.NonEmptyString;
}>
Struct
.
TypeLiteral<{ name: typeof NonEmptyString; }, []>.make(props: {
readonly name: string;
}, options?: MakeOptions): {
readonly name: string;
}
make
({
name: string
name
: "a" })
// This will throw an error because the name is empty
const Struct: Schema.Struct<{
name: typeof Schema.NonEmptyString;
}>
Struct
.
TypeLiteral<{ name: typeof NonEmptyString; }, []>.make(props: {
readonly name: string;
}, options?: MakeOptions): {
readonly name: string;
}
make
({
name: string
name
: "" })
/*
throws
ParseError: { readonly name: NonEmptyString }
└─ ["name"]
└─ NonEmptyString
└─ Predicate refinement failure
└─ Expected NonEmptyString, actual ""
*/

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)

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

@since3.10.0

Struct
({
name: typeof Schema.NonEmptyString
name
:
import Schema
Schema
.
class NonEmptyString

@since3.10.0

NonEmptyString
})
// Bypass validation during instantiation
const Struct: Schema.Struct<{
name: typeof Schema.NonEmptyString;
}>
Struct
.
TypeLiteral<{ name: typeof NonEmptyString; }, []>.make(props: {
readonly name: string;
}, options?: MakeOptions): {
readonly name: string;
}
make
({
name: string
name
: "" }, true)
// Or use the `disableValidation` option explicitly
const Struct: Schema.Struct<{
name: typeof Schema.NonEmptyString;
}>
Struct
.
TypeLiteral<{ name: typeof NonEmptyString; }, []>.make(props: {
readonly name: string;
}, options?: MakeOptions): {
readonly name: string;
}
make
({
name: string
name
: "" }, {
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)

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

@since3.10.0

Record
({
key: typeof Schema.String
key
:
import Schema
Schema
.
class String
export String

@since3.10.0

String
,
value: typeof Schema.NonEmptyString
value
:
import Schema
Schema
.
class NonEmptyString

@since3.10.0

NonEmptyString
})
// Successful creation
const Record: Schema.Record$<typeof Schema.String, typeof Schema.NonEmptyString>
Record
.
TypeLiteral<{}, [{ key: typeof String$; value: typeof NonEmptyString; }]>.make(props: void | {
readonly [x: string]: string;
}, options?: MakeOptions): {
readonly [x: string]: string;
}
make
({
a: string
a
: "a",
b: string
b
: "b" })
// This will throw an error because 'b' is empty
const Record: Schema.Record$<typeof Schema.String, typeof Schema.NonEmptyString>
Record
.
TypeLiteral<{}, [{ key: typeof String$; value: typeof NonEmptyString; }]>.make(props: void | {
readonly [x: string]: string;
}, options?: MakeOptions): {
readonly [x: string]: string;
}
make
({
a: string
a
: "a",
b: string
b
: "" })
/*
throws
ParseError: { readonly [x: string]: NonEmptyString }
└─ ["b"]
└─ NonEmptyString
└─ Predicate refinement failure
└─ Expected NonEmptyString, actual ""
*/
// Bypasses validation
const Record: Schema.Record$<typeof Schema.String, typeof Schema.NonEmptyString>
Record
.
TypeLiteral<{}, [{ key: typeof String$; value: typeof NonEmptyString; }]>.make(props: void | {
readonly [x: string]: string;
}, options?: MakeOptions): {
readonly [x: string]: string;
}
make
({
a: string
a
: "a",
b: string
b
: "" }, {
disableValidation?: boolean
disableValidation
: true })

Filters allow you to define constraints on individual values.

Example (Using Filters to Enforce Ranges)

import {
import Schema
Schema
} from "effect"
const
const MyNumber: Schema.filter<Schema.Schema<number, number, never>>
MyNumber
=
import Schema
Schema
.
class Number
export Number

@since3.10.0

Number
.
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.

@since3.10.0

between
(1, 10))
// Successful creation
const
const n: number
n
=
const MyNumber: Schema.filter<Schema.Schema<number, number, never>>
MyNumber
.
refine<number, Schema<number, number, never>>.make(a: number, options?: MakeOptions): number
make
(5)
// This will throw an error because the number is outside the valid range
const MyNumber: Schema.filter<Schema.Schema<number, number, never>>
MyNumber
.
refine<number, Schema<number, number, never>>.make(a: number, options?: MakeOptions): number
make
(20)
/*
throws
ParseError: a number between 1 and 10
└─ Predicate refinement failure
└─ Expected a number between 1 and 10, actual 20
*/
// Bypasses validation
const MyNumber: Schema.filter<Schema.Schema<number, number, never>>
MyNumber
.
refine<number, Schema<number, number, never>>.make(a: number, options?: MakeOptions): number
make
(20, {
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)

import {
import Schema
Schema
} from "effect"
const
const BrandedNumberSchema: Schema.brand<Schema.filter<Schema.Schema<number, number, never>>, "MyNumber">
BrandedNumberSchema
=
import Schema
Schema
.
class Number
export Number

@since3.10.0

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

@since3.10.0

between
(1, 10),
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>>

@paramself - The input schema to be combined with the brand.

@parambrand - The brand to apply.

@example

import * as Schema from "effect/Schema"
const Int = Schema.Number.pipe(Schema.int(), Schema.brand("Int"))
type Int = Schema.Schema.Type<typeof Int> // number & Brand<"Int">

@since3.10.0

brand
("MyNumber")
)
// Successful creation
const
const n: number & Brand<"MyNumber">
n
=
const BrandedNumberSchema: Schema.brand<Schema.filter<Schema.Schema<number, number, never>>, "MyNumber">
BrandedNumberSchema
.
BrandSchema<number & Brand<"MyNumber">, number, never>.make(a: number, options?: MakeOptions): number & Brand<"MyNumber">
make
(5)
// This will throw an error because the number is outside the valid range
const BrandedNumberSchema: Schema.brand<Schema.filter<Schema.Schema<number, number, never>>, "MyNumber">
BrandedNumberSchema
.
BrandSchema<number & Brand<"MyNumber">, number, never>.make(a: number, options?: MakeOptions): number & Brand<"MyNumber">
make
(20)
/*
throws
ParseError: a number between 1 and 10 & Brand<"MyNumber">
└─ Predicate refinement failure
└─ Expected a number between 1 and 10 & Brand<"MyNumber">, actual 20
*/
// Bypasses validation
const BrandedNumberSchema: Schema.brand<Schema.filter<Schema.Schema<number, number, never>>, "MyNumber">
BrandedNumberSchema
.
BrandSchema<number & Brand<"MyNumber">, number, never>.make(a: number, options?: MakeOptions): number & Brand<"MyNumber">
make
(20, {
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)

import {
import Schema
Schema
} from "effect"
const
const MyNumber: Schema.filter<Schema.Schema<number, number, never>>
MyNumber
=
import Schema
Schema
.
class Number
export Number

@since3.10.0

Number
.
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.

@since3.10.0

between
(1, 10))
// Create a safe constructor that validates the input
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<...>

@since3.10.0

validateEither
(
const MyNumber: Schema.filter<Schema.Schema<number, number, never>>
MyNumber
)
// Valid input returns a Right value
var console: Console

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

The module exports two specific components:

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

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

Example using the global console:

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

Example using the Console class:

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

@seesource

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

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

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

See util.format() for more information.

@sincev0.1.100

log
(
const makeMyNumber: (u: unknown, overrideOptions?: ParseOptions) => Either<number, ParseError>
makeMyNumber
(5))
/*
Output:
{ _id: 'Either', _tag: 'Right', right: 5 }
*/
// Invalid input returns a Left value with detailed error information
var console: Console

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

The module exports two specific components:

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

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

Example using the global console:

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

Example using the Console class:

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

@seesource

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

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

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

See util.format() for more information.

@sincev0.1.100

log
(
const makeMyNumber: (u: unknown, overrideOptions?: ParseOptions) => Either<number, ParseError>
makeMyNumber
(20))
/*
Output:
{
_id: 'Either',
_tag: 'Left',
left: {
_id: 'ParseError',
message: 'a number between 1 and 10\n' +
'└─ Predicate refinement failure\n' +
' └─ Expected a number between 1 and 10, actual 20'
}
}
*/

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.

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

@since3.10.0

Struct
({
name: typeof Schema.NonEmptyString
name
:
import Schema
Schema
.
class NonEmptyString

@since3.10.0

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

@since3.10.0

Number
})
// Both name and age must be provided
var console: Console

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

The module exports two specific components:

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

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

Example using the global console:

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

Example using the Console class:

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

@seesource

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

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

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

See util.format() for more information.

@sincev0.1.100

log
(
const Person: Schema.Struct<{
name: typeof Schema.NonEmptyString;
age: typeof Schema.Number;
}>
Person
.
TypeLiteral<{ name: typeof NonEmptyString; age: typeof Number$; }, []>.make(props: {
readonly name: string;
readonly age: number;
}, options?: MakeOptions): {
readonly name: string;
readonly age: number;
}
make
({
name: string
name
: "John",
age: number
age
: 30 }))
/*
Output: { name: 'John', age: 30 }
*/

Example (Struct with Default Value)

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

import {
import Schema
Schema
} from "effect"
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<":", number, never, ":", number, true, never>;
}): Schema.Struct<...> (+1 overload)

@since3.10.0

Struct
({
name: typeof Schema.NonEmptyString
name
:
import Schema
Schema
.
class NonEmptyString

@since3.10.0

NonEmptyString
,
age: Schema.PropertySignature<":", number, never, ":", number, true, never>
age
:
import Schema
Schema
.
class Number
export Number

@since3.10.0

Number
.
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
(
import Schema
Schema
.
const propertySignature: <S extends Schema.Schema.All>(self: S) => Schema.propertySignature<S>

Lifts a Schema into a PropertySignature.

@since1.0.0

@since3.10.0

propertySignature
,
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.

@since3.10.0

withConstructorDefault
(() => 0)
)
})
// The age field is optional and defaults to 0
var console: Console

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

The module exports two specific components:

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

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

Example using the global console:

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

Example using the Console class:

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

@seesource

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

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

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

See util.format() for more information.

@sincev0.1.100

log
(
const Person: Schema.Struct<{
name: typeof Schema.NonEmptyString;
age: Schema.PropertySignature<":", number, never, ":", number, true, never>;
}>
Person
.
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
({
name: string
name
: "John" }))
/*
Output:
{ name: 'John', age: 0 }
*/
var console: Console

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

The module exports two specific components:

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

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

Example using the global console:

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

Example using the Console class:

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

@seesource

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

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

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

See util.format() for more information.

@sincev0.1.100

log
(
const Person: Schema.Struct<{
name: typeof Schema.NonEmptyString;
age: Schema.PropertySignature<":", number, never, ":", number, true, never>;
}>
Person
.
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
({
name: string
name
: "John",
age?: number
age
: 30 }))
/*
Output:
{ name: 'John', age: 30 }
*/

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.

import {
import Schema
Schema
} from "effect"
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: {
name: typeof Schema.NonEmptyString;
age: Schema.PropertySignature<":", number, never, ":", number, true, never>;
timestamp: Schema.PropertySignature<":", number, never, ":", number, true, never>;
}): Schema.Struct<...> (+1 overload)

@since3.10.0

Struct
({
name: typeof Schema.NonEmptyString
name
:
import Schema
Schema
.
class NonEmptyString

@since3.10.0

NonEmptyString
,
age: Schema.PropertySignature<":", number, never, ":", number, true, never>
age
:
import Schema
Schema
.
class Number
export Number

@since3.10.0

Number
.
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
(
import Schema
Schema
.
const propertySignature: <S extends Schema.Schema.All>(self: S) => Schema.propertySignature<S>

Lifts a Schema into a PropertySignature.

@since1.0.0

@since3.10.0

propertySignature
,
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.

@since3.10.0

withConstructorDefault
(() => 0)
),
timestamp: Schema.PropertySignature<":", number, never, ":", number, true, never>
timestamp
:
import Schema
Schema
.
class Number
export Number

@since3.10.0

Number
.
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
(
import Schema
Schema
.
const propertySignature: <S extends Schema.Schema.All>(self: S) => Schema.propertySignature<S>

Lifts a Schema into a PropertySignature.

@since1.0.0

@since3.10.0

propertySignature
,
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.

@since3.10.0

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

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

getTime
())
)
})
var console: Console

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

The module exports two specific components:

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

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

Example using the global console:

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

Example using the Console class:

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

@seesource

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

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

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

See util.format() for more information.

@sincev0.1.100

log
(
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
.
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
({
name: string
name
: "name1" }))
/*
Example Output:
{ age: 0, timestamp: 1714232909221, name: 'name1' }
*/
var console: Console

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

The module exports two specific components:

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

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

Example using the global console:

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

Example using the Console class:

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

@seesource

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

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

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

See util.format() for more information.

@sincev0.1.100

log
(
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
.
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
({
name: string
name
: "name2" }))
/*
Example Output:
{ age: 0, timestamp: 1714232909227, name: 'name2' }
*/

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)

import {
import Schema
Schema
} from "effect"
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: {
name: typeof Schema.NonEmptyString;
age: Schema.PropertySignature<":", number, never, ":", number, true, never>;
timestamp: Schema.PropertySignature<":", number, never, ":", number, true, never>;
}): Schema.Struct<...> (+1 overload)

@since3.10.0

Struct
({
name: typeof Schema.NonEmptyString
name
:
import Schema
Schema
.
class NonEmptyString

@since3.10.0

NonEmptyString
,
age: Schema.PropertySignature<":", number, never, ":", number, true, never>
age
:
import Schema
Schema
.
class Number
export Number

@since3.10.0

Number
.
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
(
import Schema
Schema
.
const propertySignature: <S extends Schema.Schema.All>(self: S) => Schema.propertySignature<S>

Lifts a Schema into a PropertySignature.

@since1.0.0

@since3.10.0

propertySignature
,
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.

@since3.10.0

withConstructorDefault
(() => 0)
),
timestamp: Schema.PropertySignature<":", number, never, ":", number, true, never>
timestamp
:
import Schema
Schema
.
class Number
export Number

@since3.10.0

Number
.
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
(
import Schema
Schema
.
const propertySignature: <S extends Schema.Schema.All>(self: S) => Schema.propertySignature<S>

Lifts a Schema into a PropertySignature.

@since1.0.0

@since3.10.0

propertySignature
,
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.

@since3.10.0

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

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

getTime
())
)
})
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)

@since3.10.0

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

@since3.10.0

String
,
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
.
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
.
age: Schema.PropertySignature<":", number, never, ":", number, true, never>
age
})
var console: Console

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

The module exports two specific components:

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

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

Example using the global console:

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

Example using the Console class:

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

@seesource

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

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

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

See util.format() for more information.

@sincev0.1.100

log
(
const AnotherSchema: Schema.Struct<{
foo: typeof Schema.String;
age: Schema.PropertySignature<":", number, never, ":", number, true, never>;
}>
AnotherSchema
.
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
({
foo: string
foo
: "bar" }))
/*
Output:
{ foo: 'bar', age: 0 }
*/

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

Example (Defaults in a Class)

import {
import Schema
Schema
} from "effect"
class
class Person
Person
extends
import Schema
Schema
.
const Class: <Person>(identifier: string) => <Fields>(fieldsOr: Fields | HasFields<Fields>, annotations?: ClassAnnotations<Person, Schema.Struct<Fields extends Schema.Struct.Fields>.Type<Fields>> | undefined) => Schema.Class<...>

@example

import { Schema } from "effect"
class MyClass extends Schema.Class<MyClass>("MyClass")({
someField: Schema.String
}) {
someMethod() {
return this.someField + "bar"
}
}

@since3.10.0

Class
<
class Person
Person
>("Person")({
name: typeof Schema.NonEmptyString
name
:
import Schema
Schema
.
class NonEmptyString

@since3.10.0

NonEmptyString
,
age: Schema.PropertySignature<":", number, never, ":", number, true, never>
age
:
import Schema
Schema
.
class Number
export Number

@since3.10.0

Number
.
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
(
import Schema
Schema
.
const propertySignature: <S extends Schema.Schema.All>(self: S) => Schema.propertySignature<S>

Lifts a Schema into a PropertySignature.

@since1.0.0

@since3.10.0

propertySignature
,
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.

@since3.10.0

withConstructorDefault
(() => 0)
),
timestamp: Schema.PropertySignature<":", number, never, ":", number, true, never>
timestamp
:
import Schema
Schema
.
class Number
export Number

@since3.10.0

Number
.
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
(
import Schema
Schema
.
const propertySignature: <S extends Schema.Schema.All>(self: S) => Schema.propertySignature<S>

Lifts a Schema into a PropertySignature.

@since1.0.0

@since3.10.0

propertySignature
,
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.

@since3.10.0

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

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

getTime
())
)
}) {}
var console: Console

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

The module exports two specific components:

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

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

Example using the global console:

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

Example using the Console class:

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

@seesource

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

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

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

See util.format() for more information.

@sincev0.1.100

log
(new
constructor Person(props: {
readonly name: string;
readonly age?: number;
readonly timestamp?: number;
}, options?: MakeOptions): Person
Person
({
name: string
name
: "name1" }))
/*
Example Output:
Person { age: 0, timestamp: 1714400867208, name: 'name1' }
*/
var console: Console

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

The module exports two specific components:

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

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

Example using the global console:

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

Example using the Console class:

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

@seesource

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

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

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

See util.format() for more information.

@sincev0.1.100

log
(new
constructor Person(props: {
readonly name: string;
readonly age?: number;
readonly timestamp?: number;
}, options?: MakeOptions): Person
Person
({
name: string
name
: "name2" }))
/*
Example Output:
Person { age: 0, timestamp: 1714400867215, name: 'name2' }
*/