(
multiDocument: MultiDocument,
options?: { readonly reviver?: Reviver<Code> | undefined }
): CodeDocumentGenerates TypeScript code strings from a MultiDocument.
When to use
Use when you need to produce source code for Effect Schema definitions from a
schema representation MultiDocument.
Details
options.reviver can customize code generation for Declaration
nodes. Return undefined to fall back to the default logic, which uses
generation annotations or the encoded schema. References are
topologically sorted so non-recursive definitions are emitted before their
dependents. $ref keys are converted to sanitized JavaScript identifiers.
Example (Generating TypeScript code)
import { Schema, SchemaRepresentation } from "effect"
const Person = Schema.Struct({
name: Schema.String,
age: Schema.Int
})
const multi = SchemaRepresentation.toMultiDocument(
SchemaRepresentation.fromAST(Person.ast)
)
const codeDoc = SchemaRepresentation.toCodeDocument(multi)
console.log(codeDoc.codes[0].runtime)
// Schema.Struct({ ... })export function function toCodeDocument(
multiDocument: MultiDocument,
options?: {
readonly reviver?: Reviver<Code> | undefined
}
): CodeDocument
Generates TypeScript code strings from a
MultiDocument
.
When to use
Use when you need to produce source code for Effect Schema definitions from a
schema representation MultiDocument.
Details
options.reviver can customize code generation for
Declaration
nodes. Return undefined to fall back to the default logic, which uses
generation annotations or the encoded schema. References are
topologically sorted so non-recursive definitions are emitted before their
dependents. $ref keys are converted to sanitized JavaScript identifiers.
Example (Generating TypeScript code)
import { Schema, SchemaRepresentation } from "effect"
const Person = Schema.Struct({
name: Schema.String,
age: Schema.Int
})
const multi = SchemaRepresentation.toMultiDocument(
SchemaRepresentation.fromAST(Person.ast)
)
const codeDoc = SchemaRepresentation.toCodeDocument(multi)
console.log(codeDoc.codes[0].runtime)
// Schema.Struct({ ... })
toCodeDocument(multiDocument: MultiDocument(parameter) multiDocument: {
representations: readonly [Representation, ...Array<Representation>];
references: References;
}
multiDocument: type MultiDocument = {
readonly representations: readonly [
Representation,
...Array<Representation>
]
readonly references: References
}
One or more
Representation
s sharing a common
References
map.
When to use
Use when you use
fromASTs
to create this from multiple Schema ASTs,
toCodeDocument
to generate TypeScript code, and
toJsonSchemaMultiDocument
to convert to JSON Schema.
MultiDocument, options: {
readonly reviver?: Reviver<Code> | undefined
}
options?: {
/**
* The reviver can return `undefined` to indicate that the generation should be generated by the default logic
*/
readonly reviver?: Reviver<Code> | undefinedThe reviver can return undefined to indicate that the generation should be generated by the default logic
reviver?: type Reviver<T> = (
declaration: Declaration,
recur: (representation: Representation) => T
) => T | undefined
A callback that handles
Declaration
nodes during reconstruction
(
toSchema
) or code generation (
toCodeDocument
).
Details
Return a value to handle the declaration. Return undefined to fall back to
default behavior, which uses encodedSchema for toSchema or the
generation annotation for toCodeDocument. recur processes child
representations recursively.
Reviver<type Code = {
readonly runtime: string
readonly Type: string
}
A pair of TypeScript source strings for a schema: runtime is the
executable Schema expression, Type is the corresponding TypeScript type.
Code> | undefined
}): type CodeDocument = {
readonly codes: ReadonlyArray<Code>
readonly references: {
readonly nonRecursives: ReadonlyArray<{
readonly $ref: string
readonly code: Code
}>
readonly recursives: {
readonly [$ref: string]: Code
}
}
readonly artifacts: ReadonlyArray<Artifact>
}
The output of
toCodeDocument
: generated TypeScript code for one or
more schemas plus their shared references and auxiliary artifacts.
Details
codes contains one
Code
per input representation.
references.nonRecursives contains topologically sorted non-recursive
definitions. references.recursives contains definitions involved in cycles.
artifacts contains symbols, enums, and import statements needed by the
code.
CodeDocument {
const const artifacts: Array<Artifact>artifacts: interface Array<T>Array<type Artifact =
| {
readonly _tag: "Symbol"
readonly identifier: string
readonly generation: Code
}
| {
readonly _tag: "Enum"
readonly identifier: string
readonly generation: Code
}
| {
readonly _tag: "Import"
readonly importDeclaration: string
}
An auxiliary code artifact produced during code generation — a symbol
declaration, an enum declaration, or an import statement.
Artifact> = []
const const ts: TopologicalSortconst ts: {
nonRecursives: ReadonlyArray<{ readonly $ref: string; readonly representation: Representation }>;
recursives: { readonly [$ref: string]: Representation };
}
ts = function topologicalSort(
references: References
): TopologicalSort
topologicalSort(multiDocument: MultiDocument(parameter) multiDocument: {
representations: readonly [Representation, ...Array<Representation>];
references: References;
}
multiDocument.references: Referencesreferences)
// Phase 1: Build sanitization map with collision handling
const const sanitizedReferenceMap: Map<
string,
string
>
sanitizedReferenceMap = new var Map: MapConstructor
new <string, string>(iterable?: Iterable<readonly [string, string]> | null | undefined) => Map<string, string> (+3 overloads)
Map<string, string>()
const const uniqueSanitizedReferences: Set<string>uniqueSanitizedReferences = new var Set: SetConstructor
new <string>(iterable?: Iterable<string> | null | undefined) => Set<string> (+1 overload)
Set<string>()
const const referenceCount: Map<string, number>referenceCount = new var Map: MapConstructor
new <string, number>(iterable?: Iterable<readonly [string, number]> | null | undefined) => Map<string, number> (+3 overloads)
Map<string, number>()
// Process all references first to build the map
const const allRefs: string[]allRefs = [
...const ts: TopologicalSortconst ts: {
nonRecursives: ReadonlyArray<{ readonly $ref: string; readonly representation: Representation }>;
recursives: { readonly [$ref: string]: Representation };
}
ts.nonRecursives: ReadonlyArray<{
readonly $ref: string
readonly representation: Representation
}>
The definitions that are not recursive.
The definitions that depends on other definitions are placed after the definitions they depend on
nonRecursives.function ReadonlyArray(callbackfn: (value: { readonly $ref: string; readonly representation: Representation }, index: number, array: ReadonlyArray<{ readonly $ref: string; readonly representation: Representation }>) => U, thisArg?: any): Array<U>Calls a defined callback function on each element of an array, and returns an array that contains the results.
map(({ $ref: string$ref }) => $ref: string$ref),
...var Object: ObjectConstructorProvides functionality common to all JavaScript objects.
Object.ObjectConstructor.keys(o: {}): string[] (+1 overload)Returns the names of the enumerable string properties and methods of an object.
keys(const ts: TopologicalSortconst ts: {
nonRecursives: ReadonlyArray<{ readonly $ref: string; readonly representation: Representation }>;
recursives: { readonly [$ref: string]: Representation };
}
ts.recursives: {
readonly [$ref: string]: Representation
}
The recursive definitions (with no particular order).
recursives)
]
for (const const ref: stringref of const allRefs: string[]allRefs) {
function (local function) ensureUniqueSanitized(originalRef: string): stringensureUniqueSanitized(const ref: stringref)
}
// Phase 2: Use the map when processing references
const const nonRecursives: {
$ref: string
code: Code
}[]
nonRecursives = const ts: TopologicalSortconst ts: {
nonRecursives: ReadonlyArray<{ readonly $ref: string; readonly representation: Representation }>;
recursives: { readonly [$ref: string]: Representation };
}
ts.nonRecursives: ReadonlyArray<{
readonly $ref: string
readonly representation: Representation
}>
The definitions that are not recursive.
The definitions that depends on other definitions are placed after the definitions they depend on
nonRecursives.function ReadonlyArray(callbackfn: (value: { readonly $ref: string; readonly representation: Representation }, index: number, array: ReadonlyArray<{ readonly $ref: string; readonly representation: Representation }>) => U, thisArg?: any): Array<U>Calls a defined callback function on each element of an array, and returns an array that contains the results.
map(({ $ref: string$ref, representation: Representationrepresentation }) => ({
$ref: string$ref: const sanitizedReferenceMap: Map<
string,
string
>
sanitizedReferenceMap.Map<string, string>.get(key: string): string | undefinedReturns a specified element from the Map object. If the value that is associated to the provided key is an object, then you will get a reference to that object and any change made to that object will effectively modify it inside the Map.
get($ref: string$ref)!,
code: Code(property) code: {
runtime: string;
Type: string;
}
code: function (local function) recur(s: Representation): Coderecur(representation: Representationrepresentation)
}))
const const recursives: Record<string, Code>recursives = import RecRec.const mapEntries: {
<K extends string, A, K2 extends string, B>(
f: (a: A, key: K) => readonly [K2, B]
): (self: ReadonlyRecord<K, A>) => Record<K2, B>
<K extends string, A, K2 extends string, B>(
self: ReadonlyRecord<K, A>,
f: (a: A, key: K) => [K2, B]
): Record<K2, B>
}
mapEntries(const ts: TopologicalSortconst ts: {
nonRecursives: ReadonlyArray<{ readonly $ref: string; readonly representation: Representation }>;
recursives: { readonly [$ref: string]: Representation };
}
ts.recursives: {
readonly [$ref: string]: Representation
}
The recursive definitions (with no particular order).
recursives, (representation: Representationrepresentation, $ref: string$ref) => [
const sanitizedReferenceMap: Map<
string,
string
>
sanitizedReferenceMap.Map<string, string>.get(key: string): string | undefinedReturns a specified element from the Map object. If the value that is associated to the provided key is an object, then you will get a reference to that object and any change made to that object will effectively modify it inside the Map.
get($ref: string$ref)!,
function (local function) recur(s: Representation): Coderecur(representation: Representationrepresentation)
])
const const codes: Array<Code>codes = multiDocument: MultiDocument(parameter) multiDocument: {
representations: readonly [Representation, ...Array<Representation>];
references: References;
}
multiDocument.representations: readonly [
Representation,
...Array<Representation>
]
(property) representations: {
0: Representation;
length: number;
toString: () => string;
toLocaleString: { (): string; (locales: string | string[], options?: Intl.NumberFormatOptions & Intl.DateTimeFormatOptions): string };
concat: { (...items: Array<ConcatArray<Representation>>): Array<Representation>; (...items: Array<Representation | ConcatArray<Representation>>): Array<Representation> };
join: (separator?: string) => string;
slice: (start?: number, end?: number) => Array<Representation>;
indexOf: (searchElement: Representation, fromIndex?: number) => number;
lastIndexOf: (searchElement: Representation, fromIndex?: number) => number;
every: { (predicate: (value: Representation, index: number, array: ReadonlyArray<Representation>) => value is S, thisArg?: any): this is readonly S[]; (predicate: (value: Representation, index: number, array: ReadonlyArray<Representation>) => unk…;
some: (predicate: (value: Representation, index: number, array: ReadonlyArray<Representation>) => unknown, thisArg?: any) => boolean;
forEach: (callbackfn: (value: Representation, index: number, array: ReadonlyArray<Representation>) => void, thisArg?: any) => void;
map: (callbackfn: (value: Representation, index: number, array: ReadonlyArray<Representation>) => U, thisArg?: any) => Array<U>;
filter: { (predicate: (value: Representation, index: number, array: ReadonlyArray<Representation>) => value is S, thisArg?: any): Array<S>; (predicate: (value: Representation, index: number, array: ReadonlyArray<Representation>) => unknown, thisAr…;
reduce: { (callbackfn: (previousValue: Representation, currentValue: Representation, currentIndex: number, array: ReadonlyArray<Representation>) => Representation): Representation; (callbackfn: (previousValue: Representation, currentValue: Represe…;
reduceRight: { (callbackfn: (previousValue: Representation, currentValue: Representation, currentIndex: number, array: ReadonlyArray<Representation>) => Representation): Representation; (callbackfn: (previousValue: Representation, currentValue: Represe…;
find: { (predicate: (value: Representation, index: number, obj: ReadonlyArray<Representation>) => value is S, thisArg?: any): S | undefined; (predicate: (value: Representation, index: number, obj: ReadonlyArray<Representation>) => unknown, thisA…;
findIndex: (predicate: (value: Representation, index: number, obj: ReadonlyArray<Representation>) => unknown, thisArg?: any) => number;
entries: () => ArrayIterator<[number, Representation]>;
keys: () => ArrayIterator<number>;
values: () => ArrayIterator<Representation>;
includes: (searchElement: Representation, fromIndex?: number) => boolean;
flatMap: (callback: (this: This, value: Representation, index: number, array: Array<Representation>) => U | ReadonlyArray<U>, thisArg?: This | undefined) => Array<U>;
flat: (this: A, depth?: D | undefined) => Array<FlatArray<A, D>>;
at: (index: number) => Representation | undefined;
findLast: { (predicate: (value: Representation, index: number, array: ReadonlyArray<Representation>) => value is S, thisArg?: any): S | undefined; (predicate: (value: Representation, index: number, array: ReadonlyArray<Representation>) => unknown, t…;
findLastIndex: (predicate: (value: Representation, index: number, array: ReadonlyArray<Representation>) => unknown, thisArg?: any) => number;
toReversed: () => Array<Representation>;
toSorted: (compareFn?: ((a: Representation, b: Representation) => number) | undefined) => Array<Representation>;
toSpliced: { (start: number, deleteCount: number, ...items: Array<Representation>): Array<Representation>; (start: number, deleteCount?: number): Array<Representation> };
with: (index: number, value: Representation) => Array<Representation>;
}
representations.ReadonlyArray<Representation>.map<Code>(callbackfn: (value: Representation, index: number, array: readonly Representation[]) => Code, thisArg?: any): Code[]Calls a defined callback function on each element of an array, and returns an array that contains the results.
map(function (local function) recur(s: Representation): Coderecur)
return {
codes: Array<Code>codes,
references: {
readonly nonRecursives: ReadonlyArray<{
readonly $ref: string
readonly code: Code
}>
readonly recursives: {
readonly [$ref: string]: Code
}
}
references: {
nonRecursives: readonly {
readonly $ref: string
readonly code: Code
}[]
nonRecursives: const nonRecursives: {
$ref: string
code: Code
}[]
nonRecursives.Array<{ $ref: string; code: Code; }>.filter(predicate: (value: {
$ref: string;
code: Code;
}, index: number, array: {
$ref: string;
code: Code;
}[]) => unknown, thisArg?: any): {
$ref: string;
code: Code;
}[] (+1 overload)
Returns the elements of an array that meet the condition specified in a callback function.
filter(({ $ref: string$ref }) => (const referenceCount: Map<string, number>referenceCount.Map<string, number>.get(key: string): number | undefinedReturns a specified element from the Map object. If the value that is associated to the provided key is an object, then you will get a reference to that object and any change made to that object will effectively modify it inside the Map.
get($ref: string$ref) ?? 0) > 0),
recursives: Record<string, Code>recursives: import RecRec.const filter: {
<K extends string, A, B extends A>(
refinement: (a: NoInfer<A>, key: K) => a is B
): (
self: ReadonlyRecord<K, A>
) => Record<ReadonlyRecord.NonLiteralKey<K>, B>
<K extends string, A>(
predicate: (A: NoInfer<A>, key: K) => boolean
): (
self: ReadonlyRecord<K, A>
) => Record<ReadonlyRecord.NonLiteralKey<K>, A>
<K extends string, A, B extends A>(
self: ReadonlyRecord<K, A>,
refinement: (a: A, key: K) => a is B
): Record<ReadonlyRecord.NonLiteralKey<K>, B>
<K extends string, A>(
self: ReadonlyRecord<K, A>,
predicate: (a: A, key: K) => boolean
): Record<ReadonlyRecord.NonLiteralKey<K>, A>
}
filter(const recursives: Record<string, Code>recursives, (_: Code(parameter) _: {
runtime: string;
Type: string;
}
_, $ref: string$ref) => (const referenceCount: Map<string, number>referenceCount.Map<string, number>.get(key: string): number | undefinedReturns a specified element from the Map object. If the value that is associated to the provided key is an object, then you will get a reference to that object and any change made to that object will effectively modify it inside the Map.
get($ref: string$ref) ?? 0) > 0)
},
artifacts: Array<Artifact>artifacts
}
function function (local function) ensureUniqueSanitized(originalRef: string): stringensureUniqueSanitized(originalRef: stringoriginalRef: string): string {
// Check if already mapped (consistency)
const const sanitized: string | undefinedsanitized = const sanitizedReferenceMap: Map<
string,
string
>
sanitizedReferenceMap.Map<string, string>.get(key: string): string | undefinedReturns a specified element from the Map object. If the value that is associated to the provided key is an object, then you will get a reference to that object and any change made to that object will effectively modify it inside the Map.
get(originalRef: stringoriginalRef)
if (const sanitized: string | undefinedsanitized !== var undefinedundefined) {
return const sanitized: stringsanitized
}
// Find unique sanitized name
const const seed: stringseed = function sanitizeJavaScriptIdentifier(
s: string
): string
Converts an arbitrary string into a valid (ASCII) JavaScript identifier
starting with an uppercase letter, $, or _.
- Replaces invalid identifier characters with
_
- Uppercases a leading ASCII letter
- If the first character is a digit, prefixes
_
- Empty input becomes
_
sanitizeJavaScriptIdentifier(originalRef: stringoriginalRef)
let let candidate: stringcandidate = const seed: stringseed
let let suffix: numbersuffix = 0
while (const uniqueSanitizedReferences: Set<string>uniqueSanitizedReferences.Set<string>.has(value: string): booleanhas(let candidate: stringcandidate)) {
let candidate: stringcandidate = `${const seed: stringseed}${++let suffix: numbersuffix}`
}
const uniqueSanitizedReferences: Set<string>uniqueSanitizedReferences.Set<string>.add(value: string): Set<string>Appends a new element with a specified value to the end of the Set.
add(let candidate: stringcandidate)
const sanitizedReferenceMap: Map<
string,
string
>
sanitizedReferenceMap.Map<string, string>.set(key: string, value: string): Map<string, string>Adds a new element with a specified key and value to the Map. If an element with the same key already exists, the element will be updated.
set(originalRef: stringoriginalRef, let candidate: stringcandidate)
return let candidate: stringcandidate
}
function function (local function) addSymbol(s: symbol): stringaddSymbol(s: symbols: symbol): string {
const const identifier: stringidentifier = function (local function) ensureUniqueSanitized(originalRef: string): stringensureUniqueSanitized("_symbol")
const const key: string | undefinedkey = module globalThisglobalThis.var Symbol: SymbolConstructorSymbol.SymbolConstructor.keyFor(sym: symbol): string | undefinedReturns a key from the global symbol registry matching the given Symbol if found.
Otherwise, returns a undefined.
keyFor(s: symbols)
const const description: string | undefineddescription = s: symbols.Symbol.description: string | undefinedExpose the [[Description]] internal slot of a symbol directly.
description
const const generation: Codeconst generation: {
runtime: string;
Type: string;
}
generation = const key: string | undefinedkey === var undefinedundefined
? function makeCode(
runtime: string,
Type: string
): Code
Constructs a
Code
value from a runtime expression string and a
TypeScript type string.
makeCode(`Symbol(${const description: string | undefineddescription === var undefinedundefined ? "" : function format(input: unknown, options?: {
readonly space?: number | string | undefined;
readonly ignoreToString?: boolean | undefined;
}): string
Converts any JavaScript value into a human-readable string.
When to use
Use when you need to format arbitrary JavaScript values for debugging,
logging, or error messages.
Details
- Output is not valid JSON; use
formatJson
when you need
parseable JSON.
- Handles
BigInt, Symbol, Set, Map, Date, RegExp, and class
instances that JSON.stringify cannot represent.
- Circular references are shown as
"[Circular]" instead of throwing.
- Primitives: stringified naturally (
null, undefined, 123, true).
Strings are JSON-quoted.
- Objects with a custom
toString (not Object.prototype.toString):
toString() is called unless ignoreToString is true.
- Errors with a
cause: formatted as "<message> (cause: <cause>)".
- Iterables (
Set, Map, etc.): formatted as
ClassName([...elements]).
- Class instances: wrapped as
ClassName({...}).
Redactable values are automatically redacted.
- Arrays/objects with 0–1 entries are inline; larger ones are
pretty-printed when
space is set.
space — indentation unit (number of spaces, or a string like
"\t"). Defaults to 0 (compact).
ignoreToString — skip calling toString(). Defaults to false.
Example (Formatting compact output)
import { Formatter } from "effect"
console.log(Formatter.format({ a: 1, b: [2, 3] }))
// {"a":1,"b":[2,3]}
Example (Pretty-printed output)
import { Formatter } from "effect"
console.log(Formatter.format({ a: 1, b: [2, 3] }, { space: 2 }))
// {
// "a": 1,
// "b": [
// 2,
// 3
// ]
// }
Example (Handling circular references)
import { Formatter } from "effect"
const obj: any = { name: "loop" }
obj.self = obj
console.log(Formatter.format(obj))
// {"name":"loop","self":[Circular]}
format(const description: stringdescription)})`, `typeof ${const identifier: stringidentifier}`)
: function makeCode(
runtime: string,
Type: string
): Code
Constructs a
Code
value from a runtime expression string and a
TypeScript type string.
makeCode(`Symbol.for(${function format(input: unknown, options?: {
readonly space?: number | string | undefined;
readonly ignoreToString?: boolean | undefined;
}): string
Converts any JavaScript value into a human-readable string.
When to use
Use when you need to format arbitrary JavaScript values for debugging,
logging, or error messages.
Details
- Output is not valid JSON; use
formatJson
when you need
parseable JSON.
- Handles
BigInt, Symbol, Set, Map, Date, RegExp, and class
instances that JSON.stringify cannot represent.
- Circular references are shown as
"[Circular]" instead of throwing.
- Primitives: stringified naturally (
null, undefined, 123, true).
Strings are JSON-quoted.
- Objects with a custom
toString (not Object.prototype.toString):
toString() is called unless ignoreToString is true.
- Errors with a
cause: formatted as "<message> (cause: <cause>)".
- Iterables (
Set, Map, etc.): formatted as
ClassName([...elements]).
- Class instances: wrapped as
ClassName({...}).
Redactable values are automatically redacted.
- Arrays/objects with 0–1 entries are inline; larger ones are
pretty-printed when
space is set.
space — indentation unit (number of spaces, or a string like
"\t"). Defaults to 0 (compact).
ignoreToString — skip calling toString(). Defaults to false.
Example (Formatting compact output)
import { Formatter } from "effect"
console.log(Formatter.format({ a: 1, b: [2, 3] }))
// {"a":1,"b":[2,3]}
Example (Pretty-printed output)
import { Formatter } from "effect"
console.log(Formatter.format({ a: 1, b: [2, 3] }, { space: 2 }))
// {
// "a": 1,
// "b": [
// 2,
// 3
// ]
// }
Example (Handling circular references)
import { Formatter } from "effect"
const obj: any = { name: "loop" }
obj.self = obj
console.log(Formatter.format(obj))
// {"name":"loop","self":[Circular]}
format(const key: stringkey)})`, `typeof ${const identifier: stringidentifier}`)
const artifacts: Array<Artifact>artifacts.Array<Artifact>.push(...items: Artifact[]): numberAppends new elements to the end of an array, and returns the new length of the array.
push({ _tag: "Symbol"_tag: "Symbol", identifier: stringidentifier, generation: Code(property) generation: {
runtime: string;
Type: string;
}
generation })
return const identifier: stringidentifier
}
function function (local function) addEnum(s: Enum): stringaddEnum(s: Enum(parameter) s: {
_tag: "Enum";
annotations: Schema.Annotations.Annotations | undefined;
enums: ReadonlyArray<readonly [string, string | number]>;
}
s: Enum): string {
const const identifier: stringidentifier = function (local function) ensureUniqueSanitized(originalRef: string): stringensureUniqueSanitized("_Enum")
const artifacts: Array<Artifact>artifacts.Array<Artifact>.push(...items: Artifact[]): numberAppends new elements to the end of an array, and returns the new length of the array.
push({
_tag: "Enum"_tag: "Enum",
identifier: stringidentifier,
generation: Code(property) generation: {
runtime: string;
Type: string;
}
generation: function makeCode(
runtime: string,
Type: string
): Code
Constructs a
Code
value from a runtime expression string and a
TypeScript type string.
makeCode(
`enum ${const identifier: stringidentifier} { ${s: Enum(parameter) s: {
_tag: "Enum";
annotations: Schema.Annotations.Annotations | undefined;
enums: ReadonlyArray<readonly [string, string | number]>;
}
s.Enum.enums: readonly (readonly [string, string | number])[]enums.ReadonlyArray<readonly [string, string | number]>.map<string>(callbackfn: (value: readonly [string, string | number], index: number, array: readonly (readonly [string, string | number])[]) => string, thisArg?: any): string[]Calls a defined callback function on each element of an array, and returns an array that contains the results.
map(([name: stringname, value: string | numbervalue]) => `${function format(input: unknown, options?: {
readonly space?: number | string | undefined;
readonly ignoreToString?: boolean | undefined;
}): string
Converts any JavaScript value into a human-readable string.
When to use
Use when you need to format arbitrary JavaScript values for debugging,
logging, or error messages.
Details
- Output is not valid JSON; use
formatJson
when you need
parseable JSON.
- Handles
BigInt, Symbol, Set, Map, Date, RegExp, and class
instances that JSON.stringify cannot represent.
- Circular references are shown as
"[Circular]" instead of throwing.
- Primitives: stringified naturally (
null, undefined, 123, true).
Strings are JSON-quoted.
- Objects with a custom
toString (not Object.prototype.toString):
toString() is called unless ignoreToString is true.
- Errors with a
cause: formatted as "<message> (cause: <cause>)".
- Iterables (
Set, Map, etc.): formatted as
ClassName([...elements]).
- Class instances: wrapped as
ClassName({...}).
Redactable values are automatically redacted.
- Arrays/objects with 0–1 entries are inline; larger ones are
pretty-printed when
space is set.
space — indentation unit (number of spaces, or a string like
"\t"). Defaults to 0 (compact).
ignoreToString — skip calling toString(). Defaults to false.
Example (Formatting compact output)
import { Formatter } from "effect"
console.log(Formatter.format({ a: 1, b: [2, 3] }))
// {"a":1,"b":[2,3]}
Example (Pretty-printed output)
import { Formatter } from "effect"
console.log(Formatter.format({ a: 1, b: [2, 3] }, { space: 2 }))
// {
// "a": 1,
// "b": [
// 2,
// 3
// ]
// }
Example (Handling circular references)
import { Formatter } from "effect"
const obj: any = { name: "loop" }
obj.self = obj
console.log(Formatter.format(obj))
// {"name":"loop","self":[Circular]}
format(name: stringname)}: ${function format(input: unknown, options?: {
readonly space?: number | string | undefined;
readonly ignoreToString?: boolean | undefined;
}): string
Converts any JavaScript value into a human-readable string.
When to use
Use when you need to format arbitrary JavaScript values for debugging,
logging, or error messages.
Details
- Output is not valid JSON; use
formatJson
when you need
parseable JSON.
- Handles
BigInt, Symbol, Set, Map, Date, RegExp, and class
instances that JSON.stringify cannot represent.
- Circular references are shown as
"[Circular]" instead of throwing.
- Primitives: stringified naturally (
null, undefined, 123, true).
Strings are JSON-quoted.
- Objects with a custom
toString (not Object.prototype.toString):
toString() is called unless ignoreToString is true.
- Errors with a
cause: formatted as "<message> (cause: <cause>)".
- Iterables (
Set, Map, etc.): formatted as
ClassName([...elements]).
- Class instances: wrapped as
ClassName({...}).
Redactable values are automatically redacted.
- Arrays/objects with 0–1 entries are inline; larger ones are
pretty-printed when
space is set.
space — indentation unit (number of spaces, or a string like
"\t"). Defaults to 0 (compact).
ignoreToString — skip calling toString(). Defaults to false.
Example (Formatting compact output)
import { Formatter } from "effect"
console.log(Formatter.format({ a: 1, b: [2, 3] }))
// {"a":1,"b":[2,3]}
Example (Pretty-printed output)
import { Formatter } from "effect"
console.log(Formatter.format({ a: 1, b: [2, 3] }, { space: 2 }))
// {
// "a": 1,
// "b": [
// 2,
// 3
// ]
// }
Example (Handling circular references)
import { Formatter } from "effect"
const obj: any = { name: "loop" }
obj.self = obj
console.log(Formatter.format(obj))
// {"name":"loop","self":[Circular]}
format(value: string | numbervalue)}`).Array<string>.join(separator?: string): stringAdds all the elements of an array into a string, separated by the specified separator string.
join(", ")} }`,
`typeof ${const identifier: stringidentifier}`
)
})
return const identifier: stringidentifier
}
function function (local function) addImport(importDeclaration: string): voidaddImport(importDeclaration: stringimportDeclaration: string) {
if (!const artifacts: Array<Artifact>artifacts.Array<Artifact>.some(predicate: (value: Artifact, index: number, array: Artifact[]) => unknown, thisArg?: any): booleanDetermines whether the specified callback function returns true for any element of an array.
some((a: Artifacta) => a: Artifacta._tag: "Symbol" | "Enum" | "Import"_tag === "Import" && a: {
readonly _tag: "Import"
readonly importDeclaration: string
}
a.importDeclaration: stringimportDeclaration === importDeclaration: stringimportDeclaration)) {
const artifacts: Array<Artifact>artifacts.Array<Artifact>.push(...items: Artifact[]): numberAppends new elements to the end of an array, and returns the new length of the array.
push({ _tag: "Import"_tag: "Import", importDeclaration: stringimportDeclaration })
}
}
function function (local function) recur(s: Representation): Coderecur(s: Representations: type Representation =
| Declaration
| Reference
| Suspend
| Null
| Undefined
| Void
| Never
| Unknown
| Any
| String
| Number
| Boolean
| BigInt
| Symbol
| Literal
| UniqueSymbol
| ObjectKeyword
| Enum
| TemplateLiteral
| Arrays
| Objects
| Union
The core tagged union of all supported schema shapes.
Details
Each variant has a _tag discriminator. Switch on _tag to handle each
shape. Most variants carry optional annotations and some carry checks
for validation constraints.
Representation): type Code = {
readonly runtime: string
readonly Type: string
}
A pair of TypeScript source strings for a schema: runtime is the
executable Schema expression, Type is the corresponding TypeScript type.
Code {
const const g: Codeconst g: {
runtime: string;
Type: string;
}
g = function (local function) on(s: Representation): Codeon(s: Representations)
switch (s: Representations._tag: | "Declaration"
| "Suspend"
| "Reference"
| "Null"
| "Undefined"
| "Void"
| "Never"
| "Unknown"
| "Any"
| "String"
| "Number"
| "Boolean"
| "BigInt"
| "Symbol"
| "Literal"
| "UniqueSymbol"
| "ObjectKeyword"
| "Enum"
| "TemplateLiteral"
| "Arrays"
| "Objects"
| "Union"
_tag) {
default:
return function makeCode(
runtime: string,
Type: string
): Code
Constructs a
Code
value from a runtime expression string and a
TypeScript type string.
makeCode(
const g: Codeconst g: {
runtime: string;
Type: string;
}
g.runtime: stringruntime + function toRuntimeAnnotate(
annotations:
| Schema.Annotations.Annotations
| undefined
): string
toRuntimeAnnotate(s: Representations.annotations?: | Schema.Annotations.Annotations
| undefined
annotations) + function toRuntimeBrand(
annotations:
| Schema.Annotations.Annotations
| undefined
): string
toRuntimeBrand(s: Representations.annotations?: | Schema.Annotations.Annotations
| undefined
annotations),
const g: Codeconst g: {
runtime: string;
Type: string;
}
g.type Type: stringType + function (local function) toTypeBrand(annotations: Schema.Annotations.Annotations | undefined): stringtoTypeBrand(s: Representations.annotations?: | Schema.Annotations.Annotations
| undefined
annotations)
)
case "Reference":
return const g: Codeconst g: {
runtime: string;
Type: string;
}
g
case "Declaration":
case "String":
case "Number":
case "BigInt":
case "Arrays":
case "Objects":
case "Suspend":
return function makeCode(
runtime: string,
Type: string
): Code
Constructs a
Code
value from a runtime expression string and a
TypeScript type string.
makeCode(
const g: Codeconst g: {
runtime: string;
Type: string;
}
g.runtime: stringruntime + function toRuntimeAnnotate(
annotations:
| Schema.Annotations.Annotations
| undefined
): string
toRuntimeAnnotate(s: Representations.annotations?: | Schema.Annotations.Annotations
| undefined
annotations) + function toRuntimeBrand(
annotations:
| Schema.Annotations.Annotations
| undefined
): string
toRuntimeBrand(s: Representations.annotations?: | Schema.Annotations.Annotations
| undefined
annotations) + function (local function) toRuntimeChecks(checks: ReadonlyArray<Check<Meta>>): stringtoRuntimeChecks(s: Representations.checks: | readonly Check<DeclarationMeta>[]
| readonly []
| readonly Check<StringMeta>[]
| readonly Check<NumberMeta>[]
| readonly Check<BigIntMeta>[]
| readonly Check<ArraysMeta>[]
| readonly Check<ObjectsMeta>[]
checks),
const g: Codeconst g: {
runtime: string;
Type: string;
}
g.type Type: stringType + function (local function) toTypeBrand(annotations: Schema.Annotations.Annotations | undefined): stringtoTypeBrand(s: Representations.annotations?: | Schema.Annotations.Annotations
| undefined
annotations) + function (local function) toTypeChecks(checks: ReadonlyArray<Check<Meta>>): stringtoTypeChecks(s: Representations.checks: | readonly Check<DeclarationMeta>[]
| readonly []
| readonly Check<StringMeta>[]
| readonly Check<NumberMeta>[]
| readonly Check<BigIntMeta>[]
| readonly Check<ArraysMeta>[]
| readonly Check<ObjectsMeta>[]
checks)
)
}
}
function function (local function) on(s: Representation): Codeon(s: Representations: type Representation =
| Declaration
| Reference
| Suspend
| Null
| Undefined
| Void
| Never
| Unknown
| Any
| String
| Number
| Boolean
| BigInt
| Symbol
| Literal
| UniqueSymbol
| ObjectKeyword
| Enum
| TemplateLiteral
| Arrays
| Objects
| Union
The core tagged union of all supported schema shapes.
Details
Each variant has a _tag discriminator. Switch on _tag to handle each
shape. Most variants carry optional annotations and some carry checks
for validation constraints.
Representation): type Code = {
readonly runtime: string
readonly Type: string
}
A pair of TypeScript source strings for a schema: runtime is the
executable Schema expression, Type is the corresponding TypeScript type.
Code {
switch (s: Representations._tag: | "Declaration"
| "Suspend"
| "Reference"
| "Null"
| "Undefined"
| "Void"
| "Never"
| "Unknown"
| "Any"
| "String"
| "Number"
| "Boolean"
| "BigInt"
| "Symbol"
| "Literal"
| "UniqueSymbol"
| "ObjectKeyword"
| "Enum"
| "TemplateLiteral"
| "Arrays"
| "Objects"
| "Union"
_tag) {
case "Declaration": {
// if there is a reviver, use it to generate the generation
if (options: {
readonly reviver?: Reviver<Code> | undefined
}
options?.reviver?: Reviver<Code> | undefinedThe reviver can return undefined to indicate that the generation should be generated by the default logic
reviver !== var undefinedundefined) {
// the reviver can return `undefined` to indicate that the generation should be generated by the default logic
const const out: Code | undefinedout = options: {
readonly reviver?: Reviver<Code> | undefined
}
options.reviver?: Reviver<Code> | undefinedThe reviver can return undefined to indicate that the generation should be generated by the default logic
reviver(s: Representation(parameter) s: {
_tag: "Declaration";
annotations: Schema.Annotations.Annotations | undefined;
typeParameters: ReadonlyArray<Representation>;
checks: ReadonlyArray<Check<DeclarationMeta>>;
encodedSchema: Representation;
}
s, function (local function) recur(s: Representation): Coderecur)
if (const out: Code | undefinedout !== var undefinedundefined) {
return const out: Codeconst out: {
runtime: string;
Type: string;
}
out
}
}
// otherwise, use the generation from the annotations
const const generation: unknowngeneration = s: Representation(parameter) s: {
_tag: "Declaration";
annotations: Schema.Annotations.Annotations | undefined;
typeParameters: ReadonlyArray<Representation>;
checks: ReadonlyArray<Check<DeclarationMeta>>;
encodedSchema: Representation;
}
s.Declaration.annotations?: Schema.Annotations.Annotations | undefinedannotations?.unknowngeneration
if (
import PredicatePredicate.function isObject(
input: unknown
): input is {
[x: PropertyKey]: unknown
}
Checks whether a value is a non-null object value that is not an array.
When to use
Use to narrow unknown input to a non-null, non-array object with a
Predicate guard.
Details
This is a structural runtime check using typeof input === "object", so it
also accepts object instances such as Date, Map, class instances, and
typed arrays. It excludes null and arrays.
Example (Guarding objects)
import { Predicate } from "effect"
console.log(Predicate.isObject({ a: 1 }))
console.log(Predicate.isObject([1, 2]))
isObject(const generation: unknowngeneration) && typeof const generation: {
[x: string]: unknown
[x: number]: unknown
[x: symbol]: unknown
}
generation.__type[string | number | symbol]: unknownruntime === "string" &&
typeof const generation: {
[x: string]: unknown
[x: number]: unknown
[x: symbol]: unknown
}
generation.__type[string | number | symbol]: unknownType === "string"
) {
const const typeParameters: Array<Code>typeParameters = s: Representation(parameter) s: {
_tag: "Declaration";
annotations: Schema.Annotations.Annotations | undefined;
typeParameters: ReadonlyArray<Representation>;
checks: ReadonlyArray<Check<DeclarationMeta>>;
encodedSchema: Representation;
}
s.Declaration.typeParameters: ReadonlyArray<Representation>typeParameters.ReadonlyArray<Representation>.map<Code>(callbackfn: (value: Representation, index: number, array: readonly Representation[]) => Code, thisArg?: any): Code[]Calls a defined callback function on each element of an array, and returns an array that contains the results.
map(function (local function) recur(s: Representation): Coderecur)
if (typeof const generation: {
[x: string]: unknown
[x: number]: unknown
[x: symbol]: unknown
}
generation.__type[string | number | symbol]: unknownimportDeclaration === "string") {
function (local function) addImport(importDeclaration: string): voidaddImport(const generation: {
[x: string]: unknown
[x: number]: unknown
[x: symbol]: unknown
}
generation.__type[string | number | symbol]: stringimportDeclaration)
}
return function makeCode(
runtime: string,
Type: string
): Code
Constructs a
Code
value from a runtime expression string and a
TypeScript type string.
makeCode(
function replacePlaceholders(
template: string,
items: ReadonlyArray<string>
): string
replacePlaceholders(const generation: {
[x: string]: unknown
[x: number]: unknown
[x: symbol]: unknown
}
generation.__type[string | number | symbol]: stringruntime, const typeParameters: Array<Code>typeParameters.Array<Code>.map<string>(callbackfn: (value: Code, index: number, array: Code[]) => string, thisArg?: any): string[]Calls a defined callback function on each element of an array, and returns an array that contains the results.
map((p: Code(parameter) p: {
runtime: string;
Type: string;
}
p) => p: Code(parameter) p: {
runtime: string;
Type: string;
}
p.runtime: stringruntime)),
function replacePlaceholders(
template: string,
items: ReadonlyArray<string>
): string
replacePlaceholders(const generation: {
[x: string]: unknown
[x: number]: unknown
[x: symbol]: unknown
}
generation.__type[string | number | symbol]: stringType, const typeParameters: Array<Code>typeParameters.Array<Code>.map<string>(callbackfn: (value: Code, index: number, array: Code[]) => string, thisArg?: any): string[]Calls a defined callback function on each element of an array, and returns an array that contains the results.
map((p: Code(parameter) p: {
runtime: string;
Type: string;
}
p) => p: Code(parameter) p: {
runtime: string;
Type: string;
}
p.type Type: stringType))
)
}
// otherwise, use the generation from the encoded schema
return function (local function) recur(s: Representation): Coderecur(s: Representation(parameter) s: {
_tag: "Declaration";
annotations: Schema.Annotations.Annotations | undefined;
typeParameters: ReadonlyArray<Representation>;
checks: ReadonlyArray<Check<DeclarationMeta>>;
encodedSchema: Representation;
}
s.Declaration.encodedSchema: RepresentationencodedSchema)
}
case "Reference": {
const const sanitized: stringsanitized = function (local function) ensureUniqueSanitized(originalRef: string): stringensureUniqueSanitized(s: Representation(parameter) s: {
_tag: "Reference";
$ref: string;
}
s.Reference.$ref: string$ref)
const referenceCount: Map<string, number>referenceCount.Map<string, number>.set(key: string, value: number): Map<string, number>Adds a new element with a specified key and value to the Map. If an element with the same key already exists, the element will be updated.
set(const sanitized: stringsanitized, (const referenceCount: Map<string, number>referenceCount.Map<string, number>.get(key: string): number | undefinedReturns a specified element from the Map object. If the value that is associated to the provided key is an object, then you will get a reference to that object and any change made to that object will effectively modify it inside the Map.
get(const sanitized: stringsanitized) ?? 0) + 1)
return function makeCode(
runtime: string,
Type: string
): Code
Constructs a
Code
value from a runtime expression string and a
TypeScript type string.
makeCode(const sanitized: stringsanitized, const sanitized: stringsanitized)
}
case "Suspend": {
const const thunk: Codeconst thunk: {
runtime: string;
Type: string;
}
thunk = function (local function) recur(s: Representation): Coderecur(s: Representation(parameter) s: {
_tag: "Suspend";
annotations: Schema.Annotations.Annotations | undefined;
checks: readonly [];
thunk: Representation;
}
s.Suspend.thunk: Representationthunk)
return function makeCode(
runtime: string,
Type: string
): Code
Constructs a
Code
value from a runtime expression string and a
TypeScript type string.
makeCode(
`Schema.suspend((): Schema.Codec<${const thunk: Codeconst thunk: {
runtime: string;
Type: string;
}
thunk.type Type: stringType}> => ${const thunk: Codeconst thunk: {
runtime: string;
Type: string;
}
thunk.runtime: stringruntime})`,
const thunk: Codeconst thunk: {
runtime: string;
Type: string;
}
thunk.type Type: stringType
)
}
case "Null":
return function makeCode(
runtime: string,
Type: string
): Code
Constructs a
Code
value from a runtime expression string and a
TypeScript type string.
makeCode(`Schema.Null`, "null")
case "Undefined":
return function makeCode(
runtime: string,
Type: string
): Code
Constructs a
Code
value from a runtime expression string and a
TypeScript type string.
makeCode(`Schema.Undefined`, "undefined")
case "Void":
return function makeCode(
runtime: string,
Type: string
): Code
Constructs a
Code
value from a runtime expression string and a
TypeScript type string.
makeCode(`Schema.Void`, "void")
case "Never":
return function makeCode(
runtime: string,
Type: string
): Code
Constructs a
Code
value from a runtime expression string and a
TypeScript type string.
makeCode(`Schema.Never`, "never")
case "Unknown":
return function makeCode(
runtime: string,
Type: string
): Code
Constructs a
Code
value from a runtime expression string and a
TypeScript type string.
makeCode(`Schema.Unknown`, "unknown")
case "Any":
return function makeCode(
runtime: string,
Type: string
): Code
Constructs a
Code
value from a runtime expression string and a
TypeScript type string.
makeCode(`Schema.Any`, "any")
case "Number":
return function makeCode(
runtime: string,
Type: string
): Code
Constructs a
Code
value from a runtime expression string and a
TypeScript type string.
makeCode(`Schema.Number`, "number")
case "Boolean":
return function makeCode(
runtime: string,
Type: string
): Code
Constructs a
Code
value from a runtime expression string and a
TypeScript type string.
makeCode(`Schema.Boolean`, "boolean")
case "BigInt":
return function makeCode(
runtime: string,
Type: string
): Code
Constructs a
Code
value from a runtime expression string and a
TypeScript type string.
makeCode(`Schema.BigInt`, "bigint")
case "Symbol":
return function makeCode(
runtime: string,
Type: string
): Code
Constructs a
Code
value from a runtime expression string and a
TypeScript type string.
makeCode(`Schema.Symbol`, "symbol")
case "String": {
const const contentMediaType: string | undefinedcontentMediaType = s: Representation(parameter) s: {
_tag: "String";
annotations: Schema.Annotations.Annotations | undefined;
checks: ReadonlyArray<Check<StringMeta>>;
contentMediaType: string | undefined;
contentSchema: Representation | undefined;
}
s.String.contentMediaType?: string | undefinedcontentMediaType
const const contentSchema:
| Representation
| undefined
contentSchema = s: Representation(parameter) s: {
_tag: "String";
annotations: Schema.Annotations.Annotations | undefined;
checks: ReadonlyArray<Check<StringMeta>>;
contentMediaType: string | undefined;
contentSchema: Representation | undefined;
}
s.String.contentSchema?: Representation | undefinedcontentSchema
if (const contentMediaType: string | undefinedcontentMediaType === "application/json" && const contentSchema:
| Representation
| undefined
contentSchema !== var undefinedundefined) {
return function makeCode(
runtime: string,
Type: string
): Code
Constructs a
Code
value from a runtime expression string and a
TypeScript type string.
makeCode(`Schema.fromJsonString(${function (local function) recur(s: Representation): Coderecur(const contentSchema: RepresentationcontentSchema)})`, "string")
} else {
return function makeCode(
runtime: string,
Type: string
): Code
Constructs a
Code
value from a runtime expression string and a
TypeScript type string.
makeCode(`Schema.String`, "string")
}
}
case "Literal": {
const const literal: stringliteral = function format(input: unknown, options?: {
readonly space?: number | string | undefined;
readonly ignoreToString?: boolean | undefined;
}): string
Converts any JavaScript value into a human-readable string.
When to use
Use when you need to format arbitrary JavaScript values for debugging,
logging, or error messages.
Details
- Output is not valid JSON; use
formatJson
when you need
parseable JSON.
- Handles
BigInt, Symbol, Set, Map, Date, RegExp, and class
instances that JSON.stringify cannot represent.
- Circular references are shown as
"[Circular]" instead of throwing.
- Primitives: stringified naturally (
null, undefined, 123, true).
Strings are JSON-quoted.
- Objects with a custom
toString (not Object.prototype.toString):
toString() is called unless ignoreToString is true.
- Errors with a
cause: formatted as "<message> (cause: <cause>)".
- Iterables (
Set, Map, etc.): formatted as
ClassName([...elements]).
- Class instances: wrapped as
ClassName({...}).
Redactable values are automatically redacted.
- Arrays/objects with 0–1 entries are inline; larger ones are
pretty-printed when
space is set.
space — indentation unit (number of spaces, or a string like
"\t"). Defaults to 0 (compact).
ignoreToString — skip calling toString(). Defaults to false.
Example (Formatting compact output)
import { Formatter } from "effect"
console.log(Formatter.format({ a: 1, b: [2, 3] }))
// {"a":1,"b":[2,3]}
Example (Pretty-printed output)
import { Formatter } from "effect"
console.log(Formatter.format({ a: 1, b: [2, 3] }, { space: 2 }))
// {
// "a": 1,
// "b": [
// 2,
// 3
// ]
// }
Example (Handling circular references)
import { Formatter } from "effect"
const obj: any = { name: "loop" }
obj.self = obj
console.log(Formatter.format(obj))
// {"name":"loop","self":[Circular]}
format(s: Representation(parameter) s: {
_tag: "Literal";
annotations: Schema.Annotations.Annotations | undefined;
literal: string | number | boolean | bigint;
}
s.Literal.literal: string | number | bigint | booleanliteral)
return function makeCode(
runtime: string,
Type: string
): Code
Constructs a
Code
value from a runtime expression string and a
TypeScript type string.
makeCode(`Schema.Literal(${const literal: stringliteral})`, const literal: stringliteral)
}
case "UniqueSymbol": {
const const identifier: stringidentifier = function (local function) addSymbol(s: symbol): stringaddSymbol(s: Representation(parameter) s: {
_tag: "UniqueSymbol";
annotations: Schema.Annotations.Annotations | undefined;
symbol: symbol;
}
s.UniqueSymbol.symbol: symbolsymbol)
return function makeCode(
runtime: string,
Type: string
): Code
Constructs a
Code
value from a runtime expression string and a
TypeScript type string.
makeCode(`Schema.UniqueSymbol(${const identifier: stringidentifier})`, `typeof ${const identifier: stringidentifier}`)
}
case "ObjectKeyword":
return function makeCode(
runtime: string,
Type: string
): Code
Constructs a
Code
value from a runtime expression string and a
TypeScript type string.
makeCode(`Schema.ObjectKeyword`, "object")
case "Enum": {
const const identifier: stringidentifier = function (local function) addEnum(s: Enum): stringaddEnum(s: Representation(parameter) s: {
_tag: "Enum";
annotations: Schema.Annotations.Annotations | undefined;
enums: ReadonlyArray<readonly [string, string | number]>;
}
s)
return function makeCode(
runtime: string,
Type: string
): Code
Constructs a
Code
value from a runtime expression string and a
TypeScript type string.
makeCode(`Schema.Enum(${const identifier: stringidentifier})`, `typeof ${const identifier: stringidentifier}`)
}
case "TemplateLiteral": {
const const parts: Array<Code>parts = s: Representation(parameter) s: {
_tag: "TemplateLiteral";
annotations: Schema.Annotations.Annotations | undefined;
parts: ReadonlyArray<Representation>;
}
s.TemplateLiteral.parts: ReadonlyArray<Representation>parts.ReadonlyArray<Representation>.map<Code>(callbackfn: (value: Representation, index: number, array: readonly Representation[]) => Code, thisArg?: any): Code[]Calls a defined callback function on each element of an array, and returns an array that contains the results.
map(function (local function) recur(s: Representation): Coderecur)
const const type: stringtype = function toTypeParts(
parts: ReadonlyArray<Representation>
): ReadonlyArray<string>
toTypeParts(s: Representation(parameter) s: {
_tag: "TemplateLiteral";
annotations: Schema.Annotations.Annotations | undefined;
parts: ReadonlyArray<Representation>;
}
s.TemplateLiteral.parts: ReadonlyArray<Representation>parts).ReadonlyArray<string>.map<string>(callbackfn: (value: string, index: number, array: readonly string[]) => string, thisArg?: any): string[]Calls a defined callback function on each element of an array, and returns an array that contains the results.
map((p: stringp) => "`" + p: stringp + "`").Array<string>.join(separator?: string): stringAdds all the elements of an array into a string, separated by the specified separator string.
join(" | ")
return function makeCode(
runtime: string,
Type: string
): Code
Constructs a
Code
value from a runtime expression string and a
TypeScript type string.
makeCode(`Schema.TemplateLiteral([${const parts: Array<Code>parts.Array<Code>.map<string>(callbackfn: (value: Code, index: number, array: Code[]) => string, thisArg?: any): string[]Calls a defined callback function on each element of an array, and returns an array that contains the results.
map((p: Code(parameter) p: {
runtime: string;
Type: string;
}
p) => p: Code(parameter) p: {
runtime: string;
Type: string;
}
p.runtime: stringruntime).Array<string>.join(separator?: string): stringAdds all the elements of an array into a string, separated by the specified separator string.
join(", ")}])`, const type: stringtype)
}
case "Arrays": {
const const elements: {
isOptional: boolean
type: Code
annotations:
| Schema.Annotations.Annotations
| undefined
}[]
elements = s: Representation(parameter) s: {
_tag: "Arrays";
annotations: Schema.Annotations.Annotations | undefined;
elements: ReadonlyArray<Element>;
rest: ReadonlyArray<Representation>;
checks: ReadonlyArray<Check<ArraysMeta>>;
}
s.Arrays.elements: ReadonlyArray<Element>elements.ReadonlyArray<Element>.map<{
isOptional: boolean;
type: Code;
annotations: Schema.Annotations.Annotations | undefined;
}>(callbackfn: (value: Element, index: number, array: readonly Element[]) => {
isOptional: boolean;
type: Code;
annotations: Schema.Annotations.Annotations | undefined;
}, thisArg?: any): {
isOptional: boolean;
type: Code;
annotations: Schema.Annotations.Annotations | undefined;
}[]
Calls a defined callback function on each element of an array, and returns an array that contains the results.
map((e: Element(parameter) e: {
isOptional: boolean;
type: Representation;
annotations: Schema.Annotations.Annotations | undefined;
}
e) => {
return {
isOptional: booleanisOptional: e: Element(parameter) e: {
isOptional: boolean;
type: Representation;
annotations: Schema.Annotations.Annotations | undefined;
}
e.Element.isOptional: booleanisOptional,
type: Code(property) type: {
runtime: string;
Type: string;
}
type: function (local function) recur(s: Representation): Coderecur(e: Element(parameter) e: {
isOptional: boolean;
type: Representation;
annotations: Schema.Annotations.Annotations | undefined;
}
e.Element.type: Representationtype),
annotations: | Schema.Annotations.Annotations
| undefined
annotations: e: Element(parameter) e: {
isOptional: boolean;
type: Representation;
annotations: Schema.Annotations.Annotations | undefined;
}
e.Element.annotations?: Schema.Annotations.Annotations | undefinedannotations
}
})
const const rest: Array<Code>rest = s: Representation(parameter) s: {
_tag: "Arrays";
annotations: Schema.Annotations.Annotations | undefined;
elements: ReadonlyArray<Element>;
rest: ReadonlyArray<Representation>;
checks: ReadonlyArray<Check<ArraysMeta>>;
}
s.Arrays.rest: ReadonlyArray<Representation>rest.ReadonlyArray<Representation>.map<Code>(callbackfn: (value: Representation, index: number, array: readonly Representation[]) => Code, thisArg?: any): Code[]Calls a defined callback function on each element of an array, and returns an array that contains the results.
map(function (local function) recur(s: Representation): Coderecur)
if (import ArrArr.const isArrayNonEmpty: <A>(
self: Array<A>
) => self is NonEmptyArray<A>
Checks whether a mutable Array is non-empty, narrowing the type to
NonEmptyArray.
When to use
Use when you need the narrowed value to remain a mutable Array after proving
it has at least one element.
Example (Checking for a non-empty array)
import { Array } from "effect"
console.log(Array.isArrayNonEmpty([])) // false
console.log(Array.isArrayNonEmpty([1, 2, 3])) // true
isArrayNonEmpty(const rest: Array<Code>rest)) {
const const item: Codeconst item: {
runtime: string;
Type: string;
}
item = const rest: [Code, ...Code[]]const rest: {
0: Code;
length: number;
toString: () => string;
toLocaleString: { (): string; (locales: string | string[], options?: Intl.NumberFormatOptions & Intl.DateTimeFormatOptions): string };
pop: () => Code | undefined;
push: (...items: Array<Code>) => number;
concat: { (...items: Array<ConcatArray<Code>>): Array<Code>; (...items: Array<Code | ConcatArray<Code>>): Array<Code> };
join: (separator?: string) => string;
reverse: () => Array<Code>;
shift: () => Code | undefined;
slice: (start?: number, end?: number) => Array<Code>;
sort: (compareFn?: ((a: Code, b: Code) => number) | undefined) => [Code, ...Code[]];
splice: { (start: number, deleteCount?: number): Array<Code>; (start: number, deleteCount: number, ...items: Array<Code>): Array<Code> };
unshift: (...items: Array<Code>) => number;
indexOf: (searchElement: Code, fromIndex?: number) => number;
lastIndexOf: (searchElement: Code, fromIndex?: number) => number;
every: { (predicate: (value: Code, index: number, array: Array<Code>) => value is S, thisArg?: any): this is S[]; (predicate: (value: Code, index: number, array: Array<Code>) => unknown, thisArg?: any): boolean };
some: (predicate: (value: Code, index: number, array: Array<Code>) => unknown, thisArg?: any) => boolean;
forEach: (callbackfn: (value: Code, index: number, array: Array<Code>) => void, thisArg?: any) => void;
map: (callbackfn: (value: Code, index: number, array: Array<Code>) => U, thisArg?: any) => Array<U>;
filter: { (predicate: (value: Code, index: number, array: Array<Code>) => value is S, thisArg?: any): Array<S>; (predicate: (value: Code, index: number, array: Array<Code>) => unknown, thisArg?: any): Array<Code> };
reduce: { (callbackfn: (previousValue: Code, currentValue: Code, currentIndex: number, array: Array<Code>) => Code): Code; (callbackfn: (previousValue: Code, currentValue: Code, currentIndex: number, array: Array<Code>) => Code, initialValue: Code…;
reduceRight: { (callbackfn: (previousValue: Code, currentValue: Code, currentIndex: number, array: Array<Code>) => Code): Code; (callbackfn: (previousValue: Code, currentValue: Code, currentIndex: number, array: Array<Code>) => Code, initialValue: Code…;
find: { (predicate: (value: Code, index: number, obj: Array<Code>) => value is S, thisArg?: any): S | undefined; (predicate: (value: Code, index: number, obj: Array<Code>) => unknown, thisArg?: any): Code | undefined };
findIndex: (predicate: (value: Code, index: number, obj: Array<Code>) => unknown, thisArg?: any) => number;
fill: (value: Code, start?: number, end?: number) => [Code, ...Code[]];
copyWithin: (target: number, start: number, end?: number) => [Code, ...Code[]];
entries: () => ArrayIterator<[number, Code]>;
keys: () => ArrayIterator<number>;
values: () => ArrayIterator<Code>;
includes: (searchElement: Code, fromIndex?: number) => boolean;
flatMap: (callback: (this: This, value: Code, index: number, array: Array<Code>) => U | ReadonlyArray<U>, thisArg?: This | undefined) => Array<U>;
flat: (this: A, depth?: D | undefined) => Array<FlatArray<A, D>>;
at: (index: number) => Code | undefined;
findLast: { (predicate: (value: Code, index: number, array: Array<Code>) => value is S, thisArg?: any): S | undefined; (predicate: (value: Code, index: number, array: Array<Code>) => unknown, thisArg?: any): Code | undefined };
findLastIndex: (predicate: (value: Code, index: number, array: Array<Code>) => unknown, thisArg?: any) => number;
toReversed: () => Array<Code>;
toSorted: (compareFn?: ((a: Code, b: Code) => number) | undefined) => Array<Code>;
toSpliced: { (start: number, deleteCount: number, ...items: Array<Code>): Array<Code>; (start: number, deleteCount?: number): Array<Code> };
with: (index: number, value: Code) => Array<Code>;
}
rest[0]
if (const elements: {
isOptional: boolean
type: Code
annotations:
| Schema.Annotations.Annotations
| undefined
}[]
elements.Array<T>.length: numberGets or sets the length of the array. This is a number one higher than the highest index in the array.
length === 0 && const rest: [Code, ...Code[]]const rest: {
0: Code;
length: number;
toString: () => string;
toLocaleString: { (): string; (locales: string | string[], options?: Intl.NumberFormatOptions & Intl.DateTimeFormatOptions): string };
pop: () => Code | undefined;
push: (...items: Array<Code>) => number;
concat: { (...items: Array<ConcatArray<Code>>): Array<Code>; (...items: Array<Code | ConcatArray<Code>>): Array<Code> };
join: (separator?: string) => string;
reverse: () => Array<Code>;
shift: () => Code | undefined;
slice: (start?: number, end?: number) => Array<Code>;
sort: (compareFn?: ((a: Code, b: Code) => number) | undefined) => [Code, ...Code[]];
splice: { (start: number, deleteCount?: number): Array<Code>; (start: number, deleteCount: number, ...items: Array<Code>): Array<Code> };
unshift: (...items: Array<Code>) => number;
indexOf: (searchElement: Code, fromIndex?: number) => number;
lastIndexOf: (searchElement: Code, fromIndex?: number) => number;
every: { (predicate: (value: Code, index: number, array: Array<Code>) => value is S, thisArg?: any): this is S[]; (predicate: (value: Code, index: number, array: Array<Code>) => unknown, thisArg?: any): boolean };
some: (predicate: (value: Code, index: number, array: Array<Code>) => unknown, thisArg?: any) => boolean;
forEach: (callbackfn: (value: Code, index: number, array: Array<Code>) => void, thisArg?: any) => void;
map: (callbackfn: (value: Code, index: number, array: Array<Code>) => U, thisArg?: any) => Array<U>;
filter: { (predicate: (value: Code, index: number, array: Array<Code>) => value is S, thisArg?: any): Array<S>; (predicate: (value: Code, index: number, array: Array<Code>) => unknown, thisArg?: any): Array<Code> };
reduce: { (callbackfn: (previousValue: Code, currentValue: Code, currentIndex: number, array: Array<Code>) => Code): Code; (callbackfn: (previousValue: Code, currentValue: Code, currentIndex: number, array: Array<Code>) => Code, initialValue: Code…;
reduceRight: { (callbackfn: (previousValue: Code, currentValue: Code, currentIndex: number, array: Array<Code>) => Code): Code; (callbackfn: (previousValue: Code, currentValue: Code, currentIndex: number, array: Array<Code>) => Code, initialValue: Code…;
find: { (predicate: (value: Code, index: number, obj: Array<Code>) => value is S, thisArg?: any): S | undefined; (predicate: (value: Code, index: number, obj: Array<Code>) => unknown, thisArg?: any): Code | undefined };
findIndex: (predicate: (value: Code, index: number, obj: Array<Code>) => unknown, thisArg?: any) => number;
fill: (value: Code, start?: number, end?: number) => [Code, ...Code[]];
copyWithin: (target: number, start: number, end?: number) => [Code, ...Code[]];
entries: () => ArrayIterator<[number, Code]>;
keys: () => ArrayIterator<number>;
values: () => ArrayIterator<Code>;
includes: (searchElement: Code, fromIndex?: number) => boolean;
flatMap: (callback: (this: This, value: Code, index: number, array: Array<Code>) => U | ReadonlyArray<U>, thisArg?: This | undefined) => Array<U>;
flat: (this: A, depth?: D | undefined) => Array<FlatArray<A, D>>;
at: (index: number) => Code | undefined;
findLast: { (predicate: (value: Code, index: number, array: Array<Code>) => value is S, thisArg?: any): S | undefined; (predicate: (value: Code, index: number, array: Array<Code>) => unknown, thisArg?: any): Code | undefined };
findLastIndex: (predicate: (value: Code, index: number, array: Array<Code>) => unknown, thisArg?: any) => number;
toReversed: () => Array<Code>;
toSorted: (compareFn?: ((a: Code, b: Code) => number) | undefined) => Array<Code>;
toSpliced: { (start: number, deleteCount: number, ...items: Array<Code>): Array<Code>; (start: number, deleteCount?: number): Array<Code> };
with: (index: number, value: Code) => Array<Code>;
}
rest.length: numberlength === 1) {
return function makeCode(
runtime: string,
Type: string
): Code
Constructs a
Code
value from a runtime expression string and a
TypeScript type string.
makeCode(
`Schema.Array(${const item: Codeconst item: {
runtime: string;
Type: string;
}
item.runtime: stringruntime})`,
`ReadonlyArray<${const item: Codeconst item: {
runtime: string;
Type: string;
}
item.type Type: stringType}>`
)
}
const const post: Array<Code>post = const rest: [Code, ...Code[]]const rest: {
0: Code;
length: number;
toString: () => string;
toLocaleString: { (): string; (locales: string | string[], options?: Intl.NumberFormatOptions & Intl.DateTimeFormatOptions): string };
pop: () => Code | undefined;
push: (...items: Array<Code>) => number;
concat: { (...items: Array<ConcatArray<Code>>): Array<Code>; (...items: Array<Code | ConcatArray<Code>>): Array<Code> };
join: (separator?: string) => string;
reverse: () => Array<Code>;
shift: () => Code | undefined;
slice: (start?: number, end?: number) => Array<Code>;
sort: (compareFn?: ((a: Code, b: Code) => number) | undefined) => [Code, ...Code[]];
splice: { (start: number, deleteCount?: number): Array<Code>; (start: number, deleteCount: number, ...items: Array<Code>): Array<Code> };
unshift: (...items: Array<Code>) => number;
indexOf: (searchElement: Code, fromIndex?: number) => number;
lastIndexOf: (searchElement: Code, fromIndex?: number) => number;
every: { (predicate: (value: Code, index: number, array: Array<Code>) => value is S, thisArg?: any): this is S[]; (predicate: (value: Code, index: number, array: Array<Code>) => unknown, thisArg?: any): boolean };
some: (predicate: (value: Code, index: number, array: Array<Code>) => unknown, thisArg?: any) => boolean;
forEach: (callbackfn: (value: Code, index: number, array: Array<Code>) => void, thisArg?: any) => void;
map: (callbackfn: (value: Code, index: number, array: Array<Code>) => U, thisArg?: any) => Array<U>;
filter: { (predicate: (value: Code, index: number, array: Array<Code>) => value is S, thisArg?: any): Array<S>; (predicate: (value: Code, index: number, array: Array<Code>) => unknown, thisArg?: any): Array<Code> };
reduce: { (callbackfn: (previousValue: Code, currentValue: Code, currentIndex: number, array: Array<Code>) => Code): Code; (callbackfn: (previousValue: Code, currentValue: Code, currentIndex: number, array: Array<Code>) => Code, initialValue: Code…;
reduceRight: { (callbackfn: (previousValue: Code, currentValue: Code, currentIndex: number, array: Array<Code>) => Code): Code; (callbackfn: (previousValue: Code, currentValue: Code, currentIndex: number, array: Array<Code>) => Code, initialValue: Code…;
find: { (predicate: (value: Code, index: number, obj: Array<Code>) => value is S, thisArg?: any): S | undefined; (predicate: (value: Code, index: number, obj: Array<Code>) => unknown, thisArg?: any): Code | undefined };
findIndex: (predicate: (value: Code, index: number, obj: Array<Code>) => unknown, thisArg?: any) => number;
fill: (value: Code, start?: number, end?: number) => [Code, ...Code[]];
copyWithin: (target: number, start: number, end?: number) => [Code, ...Code[]];
entries: () => ArrayIterator<[number, Code]>;
keys: () => ArrayIterator<number>;
values: () => ArrayIterator<Code>;
includes: (searchElement: Code, fromIndex?: number) => boolean;
flatMap: (callback: (this: This, value: Code, index: number, array: Array<Code>) => U | ReadonlyArray<U>, thisArg?: This | undefined) => Array<U>;
flat: (this: A, depth?: D | undefined) => Array<FlatArray<A, D>>;
at: (index: number) => Code | undefined;
findLast: { (predicate: (value: Code, index: number, array: Array<Code>) => value is S, thisArg?: any): S | undefined; (predicate: (value: Code, index: number, array: Array<Code>) => unknown, thisArg?: any): Code | undefined };
findLastIndex: (predicate: (value: Code, index: number, array: Array<Code>) => unknown, thisArg?: any) => number;
toReversed: () => Array<Code>;
toSorted: (compareFn?: ((a: Code, b: Code) => number) | undefined) => Array<Code>;
toSpliced: { (start: number, deleteCount: number, ...items: Array<Code>): Array<Code>; (start: number, deleteCount?: number): Array<Code> };
with: (index: number, value: Code) => Array<Code>;
}
rest.Array<Code>.slice(start?: number, end?: number): Code[]Returns a copy of a section of an array.
For both start and end, a negative index can be used to indicate an offset from the end of the array.
For example, -2 refers to the second to last element of the array.
slice(1)
return function makeCode(
runtime: string,
Type: string
): Code
Constructs a
Code
value from a runtime expression string and a
TypeScript type string.
makeCode(
`Schema.TupleWithRest(Schema.Tuple([${
const elements: {
isOptional: boolean
type: Code
annotations:
| Schema.Annotations.Annotations
| undefined
}[]
elements.Array<{ isOptional: boolean; type: Code; annotations: Annotations.Annotations | undefined; }>.map<string>(callbackfn: (value: {
isOptional: boolean;
type: Code;
annotations: Schema.Annotations.Annotations | undefined;
}, index: number, array: {
isOptional: boolean;
type: Code;
annotations: Schema.Annotations.Annotations | undefined;
}[]) => string, thisArg?: any): string[]
Calls a defined callback function on each element of an array, and returns an array that contains the results.
map((e: {
isOptional: boolean
type: Code
annotations:
| Schema.Annotations.Annotations
| undefined
}
e) =>
function toRuntimeIsOptional(
isOptional: boolean,
runtime: string
): string
toRuntimeIsOptional(e: {
isOptional: boolean
type: Code
annotations:
| Schema.Annotations.Annotations
| undefined
}
e.isOptional: booleanisOptional, e: {
isOptional: boolean
type: Code
annotations:
| Schema.Annotations.Annotations
| undefined
}
e.type: Code(property) type: {
runtime: string;
Type: string;
}
type.runtime: stringruntime) + function toRuntimeAnnotateKey(
annotations:
| Schema.Annotations.Annotations
| undefined
): string
toRuntimeAnnotateKey(e: {
isOptional: boolean
type: Code
annotations:
| Schema.Annotations.Annotations
| undefined
}
e.annotations: | Schema.Annotations.Annotations
| undefined
annotations)
).Array<string>.join(separator?: string): stringAdds all the elements of an array into a string, separated by the specified separator string.
join(", ")
}]), [${const rest: [Code, ...Code[]]const rest: {
0: Code;
length: number;
toString: () => string;
toLocaleString: { (): string; (locales: string | string[], options?: Intl.NumberFormatOptions & Intl.DateTimeFormatOptions): string };
pop: () => Code | undefined;
push: (...items: Array<Code>) => number;
concat: { (...items: Array<ConcatArray<Code>>): Array<Code>; (...items: Array<Code | ConcatArray<Code>>): Array<Code> };
join: (separator?: string) => string;
reverse: () => Array<Code>;
shift: () => Code | undefined;
slice: (start?: number, end?: number) => Array<Code>;
sort: (compareFn?: ((a: Code, b: Code) => number) | undefined) => [Code, ...Code[]];
splice: { (start: number, deleteCount?: number): Array<Code>; (start: number, deleteCount: number, ...items: Array<Code>): Array<Code> };
unshift: (...items: Array<Code>) => number;
indexOf: (searchElement: Code, fromIndex?: number) => number;
lastIndexOf: (searchElement: Code, fromIndex?: number) => number;
every: { (predicate: (value: Code, index: number, array: Array<Code>) => value is S, thisArg?: any): this is S[]; (predicate: (value: Code, index: number, array: Array<Code>) => unknown, thisArg?: any): boolean };
some: (predicate: (value: Code, index: number, array: Array<Code>) => unknown, thisArg?: any) => boolean;
forEach: (callbackfn: (value: Code, index: number, array: Array<Code>) => void, thisArg?: any) => void;
map: (callbackfn: (value: Code, index: number, array: Array<Code>) => U, thisArg?: any) => Array<U>;
filter: { (predicate: (value: Code, index: number, array: Array<Code>) => value is S, thisArg?: any): Array<S>; (predicate: (value: Code, index: number, array: Array<Code>) => unknown, thisArg?: any): Array<Code> };
reduce: { (callbackfn: (previousValue: Code, currentValue: Code, currentIndex: number, array: Array<Code>) => Code): Code; (callbackfn: (previousValue: Code, currentValue: Code, currentIndex: number, array: Array<Code>) => Code, initialValue: Code…;
reduceRight: { (callbackfn: (previousValue: Code, currentValue: Code, currentIndex: number, array: Array<Code>) => Code): Code; (callbackfn: (previousValue: Code, currentValue: Code, currentIndex: number, array: Array<Code>) => Code, initialValue: Code…;
find: { (predicate: (value: Code, index: number, obj: Array<Code>) => value is S, thisArg?: any): S | undefined; (predicate: (value: Code, index: number, obj: Array<Code>) => unknown, thisArg?: any): Code | undefined };
findIndex: (predicate: (value: Code, index: number, obj: Array<Code>) => unknown, thisArg?: any) => number;
fill: (value: Code, start?: number, end?: number) => [Code, ...Code[]];
copyWithin: (target: number, start: number, end?: number) => [Code, ...Code[]];
entries: () => ArrayIterator<[number, Code]>;
keys: () => ArrayIterator<number>;
values: () => ArrayIterator<Code>;
includes: (searchElement: Code, fromIndex?: number) => boolean;
flatMap: (callback: (this: This, value: Code, index: number, array: Array<Code>) => U | ReadonlyArray<U>, thisArg?: This | undefined) => Array<U>;
flat: (this: A, depth?: D | undefined) => Array<FlatArray<A, D>>;
at: (index: number) => Code | undefined;
findLast: { (predicate: (value: Code, index: number, array: Array<Code>) => value is S, thisArg?: any): S | undefined; (predicate: (value: Code, index: number, array: Array<Code>) => unknown, thisArg?: any): Code | undefined };
findLastIndex: (predicate: (value: Code, index: number, array: Array<Code>) => unknown, thisArg?: any) => number;
toReversed: () => Array<Code>;
toSorted: (compareFn?: ((a: Code, b: Code) => number) | undefined) => Array<Code>;
toSpliced: { (start: number, deleteCount: number, ...items: Array<Code>): Array<Code>; (start: number, deleteCount?: number): Array<Code> };
with: (index: number, value: Code) => Array<Code>;
}
rest.Array<Code>.map<string>(callbackfn: (value: Code, index: number, array: Code[]) => string, thisArg?: any): string[]Calls a defined callback function on each element of an array, and returns an array that contains the results.
map((r: Code(parameter) r: {
runtime: string;
Type: string;
}
r) => r: Code(parameter) r: {
runtime: string;
Type: string;
}
r.runtime: stringruntime).Array<string>.join(separator?: string): stringAdds all the elements of an array into a string, separated by the specified separator string.
join(", ")}])`,
`readonly [${
const elements: {
isOptional: boolean
type: Code
annotations:
| Schema.Annotations.Annotations
| undefined
}[]
elements.Array<{ isOptional: boolean; type: Code; annotations: Annotations.Annotations | undefined; }>.map<string>(callbackfn: (value: {
isOptional: boolean;
type: Code;
annotations: Schema.Annotations.Annotations | undefined;
}, index: number, array: {
isOptional: boolean;
type: Code;
annotations: Schema.Annotations.Annotations | undefined;
}[]) => string, thisArg?: any): string[]
Calls a defined callback function on each element of an array, and returns an array that contains the results.
map((e: {
isOptional: boolean
type: Code
annotations:
| Schema.Annotations.Annotations
| undefined
}
e) => function toTypeIsOptional(
isOptional: boolean,
type: string
): string
toTypeIsOptional(e: {
isOptional: boolean
type: Code
annotations:
| Schema.Annotations.Annotations
| undefined
}
e.isOptional: booleanisOptional, e: {
isOptional: boolean
type: Code
annotations:
| Schema.Annotations.Annotations
| undefined
}
e.type: Code(property) type: {
runtime: string;
Type: string;
}
type.type Type: stringType)).Array<string>.join(separator?: string): stringAdds all the elements of an array into a string, separated by the specified separator string.
join(", ")
}, ...Array<${const item: Codeconst item: {
runtime: string;
Type: string;
}
item.type Type: stringType}>${const post: Array<Code>post.Array<T>.length: numberGets or sets the length of the array. This is a number one higher than the highest index in the array.
length > 0 ? `, ${const post: Array<Code>post.Array<Code>.map<string>(callbackfn: (value: Code, index: number, array: Code[]) => string, thisArg?: any): string[]Calls a defined callback function on each element of an array, and returns an array that contains the results.
map((p: Code(parameter) p: {
runtime: string;
Type: string;
}
p) => p: Code(parameter) p: {
runtime: string;
Type: string;
}
p.type Type: stringType).Array<string>.join(separator?: string): stringAdds all the elements of an array into a string, separated by the specified separator string.
join(", ")}` : ""}]`
)
}
return function makeCode(
runtime: string,
Type: string
): Code
Constructs a
Code
value from a runtime expression string and a
TypeScript type string.
makeCode(
`Schema.Tuple([${
const elements: {
isOptional: boolean
type: Code
annotations:
| Schema.Annotations.Annotations
| undefined
}[]
elements.Array<{ isOptional: boolean; type: Code; annotations: Annotations.Annotations | undefined; }>.map<string>(callbackfn: (value: {
isOptional: boolean;
type: Code;
annotations: Schema.Annotations.Annotations | undefined;
}, index: number, array: {
isOptional: boolean;
type: Code;
annotations: Schema.Annotations.Annotations | undefined;
}[]) => string, thisArg?: any): string[]
Calls a defined callback function on each element of an array, and returns an array that contains the results.
map((e: {
isOptional: boolean
type: Code
annotations:
| Schema.Annotations.Annotations
| undefined
}
e) => function toRuntimeIsOptional(
isOptional: boolean,
runtime: string
): string
toRuntimeIsOptional(e: {
isOptional: boolean
type: Code
annotations:
| Schema.Annotations.Annotations
| undefined
}
e.isOptional: booleanisOptional, e: {
isOptional: boolean
type: Code
annotations:
| Schema.Annotations.Annotations
| undefined
}
e.type: Code(property) type: {
runtime: string;
Type: string;
}
type.runtime: stringruntime) + function toRuntimeAnnotateKey(
annotations:
| Schema.Annotations.Annotations
| undefined
): string
toRuntimeAnnotateKey(e: {
isOptional: boolean
type: Code
annotations:
| Schema.Annotations.Annotations
| undefined
}
e.annotations: | Schema.Annotations.Annotations
| undefined
annotations))
.Array<string>.join(separator?: string): stringAdds all the elements of an array into a string, separated by the specified separator string.
join(", ")
}])`,
`readonly [${const elements: {
isOptional: boolean
type: Code
annotations:
| Schema.Annotations.Annotations
| undefined
}[]
elements.Array<{ isOptional: boolean; type: Code; annotations: Annotations.Annotations | undefined; }>.map<string>(callbackfn: (value: {
isOptional: boolean;
type: Code;
annotations: Schema.Annotations.Annotations | undefined;
}, index: number, array: {
isOptional: boolean;
type: Code;
annotations: Schema.Annotations.Annotations | undefined;
}[]) => string, thisArg?: any): string[]
Calls a defined callback function on each element of an array, and returns an array that contains the results.
map((e: {
isOptional: boolean
type: Code
annotations:
| Schema.Annotations.Annotations
| undefined
}
e) => function toTypeIsOptional(
isOptional: boolean,
type: string
): string
toTypeIsOptional(e: {
isOptional: boolean
type: Code
annotations:
| Schema.Annotations.Annotations
| undefined
}
e.isOptional: booleanisOptional, e: {
isOptional: boolean
type: Code
annotations:
| Schema.Annotations.Annotations
| undefined
}
e.type: Code(property) type: {
runtime: string;
Type: string;
}
type.type Type: stringType)).Array<string>.join(separator?: string): stringAdds all the elements of an array into a string, separated by the specified separator string.
join(", ")}]`
)
}
case "Objects": {
const const pss: Array<Code>pss = s: Representation(parameter) s: {
_tag: "Objects";
annotations: Schema.Annotations.Annotations | undefined;
propertySignatures: ReadonlyArray<PropertySignature>;
indexSignatures: ReadonlyArray<IndexSignature>;
checks: ReadonlyArray<Check<ObjectsMeta>>;
}
s.Objects.propertySignatures: ReadonlyArray<PropertySignature>propertySignatures.ReadonlyArray<PropertySignature>.map<Code>(callbackfn: (value: PropertySignature, index: number, array: readonly PropertySignature[]) => Code, thisArg?: any): Code[]Calls a defined callback function on each element of an array, and returns an array that contains the results.
map((p: PropertySignature(parameter) p: {
name: PropertyKey;
type: Representation;
isOptional: boolean;
isMutable: boolean;
annotations: Schema.Annotations.Annotations | undefined;
}
p) => {
const const isSymbol: booleanisSymbol = typeof p: PropertySignature(parameter) p: {
name: PropertyKey;
type: Representation;
isOptional: boolean;
isMutable: boolean;
annotations: Schema.Annotations.Annotations | undefined;
}
p.PropertySignature.name: PropertyKeyname === "symbol"
const const name: stringname = const isSymbol: booleanisSymbol ? function (local function) addSymbol(s: symbol): stringaddSymbol(p: PropertySignature(parameter) p: {
name: PropertyKey;
type: Representation;
isOptional: boolean;
isMutable: boolean;
annotations: Schema.Annotations.Annotations | undefined;
}
p.PropertySignature.name: symbolname) : function formatPropertyKey(name: PropertyKey): stringformatPropertyKey(p: PropertySignature(parameter) p: {
name: PropertyKey;
type: Representation;
isOptional: boolean;
isMutable: boolean;
annotations: Schema.Annotations.Annotations | undefined;
}
p.PropertySignature.name: string | numbername)
const const nameType: stringnameType = function toTypeIsOptional(
isOptional: boolean,
type: string
): string
toTypeIsOptional(
p: PropertySignature(parameter) p: {
name: PropertyKey;
type: Representation;
isOptional: boolean;
isMutable: boolean;
annotations: Schema.Annotations.Annotations | undefined;
}
p.PropertySignature.isOptional: booleanisOptional,
function toTypeIsMutable(
isMutable: boolean,
type: string
): string
toTypeIsMutable(p: PropertySignature(parameter) p: {
name: PropertyKey;
type: Representation;
isOptional: boolean;
isMutable: boolean;
annotations: Schema.Annotations.Annotations | undefined;
}
p.PropertySignature.isMutable: booleanisMutable, const isSymbol: booleanisSymbol ? `[typeof ${const name: stringname}]` : const name: stringname)
)
const const type: Codeconst type: {
runtime: string;
Type: string;
}
type = function (local function) recur(s: Representation): Coderecur(p: PropertySignature(parameter) p: {
name: PropertyKey;
type: Representation;
isOptional: boolean;
isMutable: boolean;
annotations: Schema.Annotations.Annotations | undefined;
}
p.PropertySignature.type: Representationtype)
return function makeCode(
runtime: string,
Type: string
): Code
Constructs a
Code
value from a runtime expression string and a
TypeScript type string.
makeCode(
`${const isSymbol: booleanisSymbol ? `[${const name: stringname}]` : const name: stringname}: ${
function toRuntimeIsOptional(
isOptional: boolean,
runtime: string
): string
toRuntimeIsOptional(p: PropertySignature(parameter) p: {
name: PropertyKey;
type: Representation;
isOptional: boolean;
isMutable: boolean;
annotations: Schema.Annotations.Annotations | undefined;
}
p.PropertySignature.isOptional: booleanisOptional, function toRuntimeIsMutable(
isMutable: boolean,
runtime: string
): string
toRuntimeIsMutable(p: PropertySignature(parameter) p: {
name: PropertyKey;
type: Representation;
isOptional: boolean;
isMutable: boolean;
annotations: Schema.Annotations.Annotations | undefined;
}
p.PropertySignature.isMutable: booleanisMutable, const type: Codeconst type: {
runtime: string;
Type: string;
}
type.runtime: stringruntime))
}` +
function toRuntimeAnnotateKey(
annotations:
| Schema.Annotations.Annotations
| undefined
): string
toRuntimeAnnotateKey(p: PropertySignature(parameter) p: {
name: PropertyKey;
type: Representation;
isOptional: boolean;
isMutable: boolean;
annotations: Schema.Annotations.Annotations | undefined;
}
p.PropertySignature.annotations?: Schema.Annotations.Annotations | undefinedannotations),
`${const nameType: stringnameType}: ${const type: Codeconst type: {
runtime: string;
Type: string;
}
type.type Type: stringType}`
)
})
const const iss: {
parameter: Code
type: Code
}[]
iss = s: Representation(parameter) s: {
_tag: "Objects";
annotations: Schema.Annotations.Annotations | undefined;
propertySignatures: ReadonlyArray<PropertySignature>;
indexSignatures: ReadonlyArray<IndexSignature>;
checks: ReadonlyArray<Check<ObjectsMeta>>;
}
s.Objects.indexSignatures: ReadonlyArray<IndexSignature>indexSignatures.ReadonlyArray<IndexSignature>.map<{
parameter: Code;
type: Code;
}>(callbackfn: (value: IndexSignature, index: number, array: readonly IndexSignature[]) => {
parameter: Code;
type: Code;
}, thisArg?: any): {
parameter: Code;
type: Code;
}[]
Calls a defined callback function on each element of an array, and returns an array that contains the results.
map((is: IndexSignature(parameter) is: {
parameter: Representation;
type: Representation;
}
is) => {
return {
parameter: Code(property) parameter: {
runtime: string;
Type: string;
}
parameter: function (local function) recur(s: Representation): Coderecur(is: IndexSignature(parameter) is: {
parameter: Representation;
type: Representation;
}
is.IndexSignature.parameter: Representationparameter),
type: Code(property) type: {
runtime: string;
Type: string;
}
type: function (local function) recur(s: Representation): Coderecur(is: IndexSignature(parameter) is: {
parameter: Representation;
type: Representation;
}
is.IndexSignature.type: Representationtype)
}
})
if (const iss: {
parameter: Code
type: Code
}[]
iss.Array<T>.length: numberGets or sets the length of the array. This is a number one higher than the highest index in the array.
length === 0) {
// 1) Only properties -> Struct
return function makeCode(
runtime: string,
Type: string
): Code
Constructs a
Code
value from a runtime expression string and a
TypeScript type string.
makeCode(
`Schema.Struct({ ${const pss: Array<Code>pss.Array<Code>.map<string>(callbackfn: (value: Code, index: number, array: Code[]) => string, thisArg?: any): string[]Calls a defined callback function on each element of an array, and returns an array that contains the results.
map((p: Code(parameter) p: {
runtime: string;
Type: string;
}
p) => p: Code(parameter) p: {
runtime: string;
Type: string;
}
p.runtime: stringruntime).Array<string>.join(separator?: string): stringAdds all the elements of an array into a string, separated by the specified separator string.
join(", ")} })`,
`{ ${const pss: Array<Code>pss.Array<Code>.map<string>(callbackfn: (value: Code, index: number, array: Code[]) => string, thisArg?: any): string[]Calls a defined callback function on each element of an array, and returns an array that contains the results.
map((p: Code(parameter) p: {
runtime: string;
Type: string;
}
p) => p: Code(parameter) p: {
runtime: string;
Type: string;
}
p.type Type: stringType).Array<string>.join(separator?: string): stringAdds all the elements of an array into a string, separated by the specified separator string.
join(", ")} }`
)
} else if (const pss: Array<Code>pss.Array<T>.length: numberGets or sets the length of the array. This is a number one higher than the highest index in the array.
length === 0 && const iss: {
parameter: Code
type: Code
}[]
iss.Array<T>.length: numberGets or sets the length of the array. This is a number one higher than the highest index in the array.
length === 1) {
// 2) Only one index signature and no properties -> Record
return function makeCode(
runtime: string,
Type: string
): Code
Constructs a
Code
value from a runtime expression string and a
TypeScript type string.
makeCode(
`Schema.Record(${const iss: {
parameter: Code
type: Code
}[]
iss[0].parameter: Code(property) parameter: {
runtime: string;
Type: string;
}
parameter.runtime: stringruntime}, ${const iss: {
parameter: Code
type: Code
}[]
iss[0].type: Code(property) type: {
runtime: string;
Type: string;
}
type.runtime: stringruntime})`,
`{ readonly [x: ${const iss: {
parameter: Code
type: Code
}[]
iss[0].parameter: Code(property) parameter: {
runtime: string;
Type: string;
}
parameter.type Type: stringType}]: ${const iss: {
parameter: Code
type: Code
}[]
iss[0].type: Code(property) type: {
runtime: string;
Type: string;
}
type.type Type: stringType} }`
)
} else {
// 3) Properties + index signatures -> StructWithRest
return function makeCode(
runtime: string,
Type: string
): Code
Constructs a
Code
value from a runtime expression string and a
TypeScript type string.
makeCode(
`Schema.StructWithRest(Schema.Struct({ ${const pss: Array<Code>pss.Array<Code>.map<string>(callbackfn: (value: Code, index: number, array: Code[]) => string, thisArg?: any): string[]Calls a defined callback function on each element of an array, and returns an array that contains the results.
map((p: Code(parameter) p: {
runtime: string;
Type: string;
}
p) => p: Code(parameter) p: {
runtime: string;
Type: string;
}
p.runtime: stringruntime).Array<string>.join(separator?: string): stringAdds all the elements of an array into a string, separated by the specified separator string.
join(", ")} }), [${
const iss: {
parameter: Code
type: Code
}[]
iss.Array<{ parameter: Code; type: Code; }>.map<string>(callbackfn: (value: {
parameter: Code;
type: Code;
}, index: number, array: {
parameter: Code;
type: Code;
}[]) => string, thisArg?: any): string[]
Calls a defined callback function on each element of an array, and returns an array that contains the results.
map((is: {
parameter: Code
type: Code
}
is) => `Schema.Record(${is: {
parameter: Code
type: Code
}
is.parameter: Code(property) parameter: {
runtime: string;
Type: string;
}
parameter.runtime: stringruntime}, ${is: {
parameter: Code
type: Code
}
is.type: Code(property) type: {
runtime: string;
Type: string;
}
type.runtime: stringruntime})`).Array<string>.join(separator?: string): stringAdds all the elements of an array into a string, separated by the specified separator string.
join(", ")
}])`,
`{ ${const pss: Array<Code>pss.Array<Code>.map<string>(callbackfn: (value: Code, index: number, array: Code[]) => string, thisArg?: any): string[]Calls a defined callback function on each element of an array, and returns an array that contains the results.
map((p: Code(parameter) p: {
runtime: string;
Type: string;
}
p) => p: Code(parameter) p: {
runtime: string;
Type: string;
}
p.type Type: stringType).Array<string>.join(separator?: string): stringAdds all the elements of an array into a string, separated by the specified separator string.
join(", ")}, ${
const iss: {
parameter: Code
type: Code
}[]
iss.Array<{ parameter: Code; type: Code; }>.map<string>(callbackfn: (value: {
parameter: Code;
type: Code;
}, index: number, array: {
parameter: Code;
type: Code;
}[]) => string, thisArg?: any): string[]
Calls a defined callback function on each element of an array, and returns an array that contains the results.
map((is: {
parameter: Code
type: Code
}
is) => `readonly [x: ${is: {
parameter: Code
type: Code
}
is.parameter: Code(property) parameter: {
runtime: string;
Type: string;
}
parameter.type Type: stringType}]: ${is: {
parameter: Code
type: Code
}
is.type: Code(property) type: {
runtime: string;
Type: string;
}
type.type Type: stringType}`).Array<string>.join(separator?: string): stringAdds all the elements of an array into a string, separated by the specified separator string.
join(", ")
} }`
)
}
}
case "Union": {
if (s: Representation(parameter) s: {
_tag: "Union";
annotations: Schema.Annotations.Annotations | undefined;
types: ReadonlyArray<Representation>;
mode: "anyOf" | "oneOf";
}
s.Union.types: ReadonlyArray<Representation>types.ReadonlyArray<T>.length: numberGets the length of the array. This is a number one higher than the highest element defined in an array.
length === 0) {
return function makeCode(
runtime: string,
Type: string
): Code
Constructs a
Code
value from a runtime expression string and a
TypeScript type string.
makeCode("Schema.Never", "never")
}
if (s: Representation(parameter) s: {
_tag: "Union";
annotations: Schema.Annotations.Annotations | undefined;
types: ReadonlyArray<Representation>;
mode: "anyOf" | "oneOf";
}
s.Union.types: ReadonlyArray<Representation>types.ReadonlyArray<Representation>.every<Literal>(predicate: (value: Representation, index: number, array: readonly Representation[]) => value is Literal, thisArg?: any): this is readonly S[] (+1 overload)Determines whether all the members of an array satisfy the specified test.
every((t: Representationt) => t: Representationt._tag: | "Declaration"
| "Suspend"
| "Reference"
| "Null"
| "Undefined"
| "Void"
| "Never"
| "Unknown"
| "Any"
| "String"
| "Number"
| "Boolean"
| "BigInt"
| "Symbol"
| "Literal"
| "UniqueSymbol"
| "ObjectKeyword"
| "Enum"
| "TemplateLiteral"
| "Arrays"
| "Objects"
| "Union"
_tag === "Literal")) {
const const literals: string[]literals = s: Representation(parameter) s: {
_tag: "Union";
annotations: Schema.Annotations.Annotations | undefined;
types: ReadonlyArray<Representation>;
mode: "anyOf" | "oneOf";
}
s.Union.types: ReadonlyArray<Representation>types.ReadonlyArray<Literal>.map<string>(callbackfn: (value: Literal, index: number, array: readonly Literal[]) => string, thisArg?: any): string[]Calls a defined callback function on each element of an array, and returns an array that contains the results.
map((l: Literal(parameter) l: {
_tag: "Literal";
annotations: Schema.Annotations.Annotations | undefined;
literal: string | number | boolean | bigint;
}
l) => function format(input: unknown, options?: {
readonly space?: number | string | undefined;
readonly ignoreToString?: boolean | undefined;
}): string
Converts any JavaScript value into a human-readable string.
When to use
Use when you need to format arbitrary JavaScript values for debugging,
logging, or error messages.
Details
- Output is not valid JSON; use
formatJson
when you need
parseable JSON.
- Handles
BigInt, Symbol, Set, Map, Date, RegExp, and class
instances that JSON.stringify cannot represent.
- Circular references are shown as
"[Circular]" instead of throwing.
- Primitives: stringified naturally (
null, undefined, 123, true).
Strings are JSON-quoted.
- Objects with a custom
toString (not Object.prototype.toString):
toString() is called unless ignoreToString is true.
- Errors with a
cause: formatted as "<message> (cause: <cause>)".
- Iterables (
Set, Map, etc.): formatted as
ClassName([...elements]).
- Class instances: wrapped as
ClassName({...}).
Redactable values are automatically redacted.
- Arrays/objects with 0–1 entries are inline; larger ones are
pretty-printed when
space is set.
space — indentation unit (number of spaces, or a string like
"\t"). Defaults to 0 (compact).
ignoreToString — skip calling toString(). Defaults to false.
Example (Formatting compact output)
import { Formatter } from "effect"
console.log(Formatter.format({ a: 1, b: [2, 3] }))
// {"a":1,"b":[2,3]}
Example (Pretty-printed output)
import { Formatter } from "effect"
console.log(Formatter.format({ a: 1, b: [2, 3] }, { space: 2 }))
// {
// "a": 1,
// "b": [
// 2,
// 3
// ]
// }
Example (Handling circular references)
import { Formatter } from "effect"
const obj: any = { name: "loop" }
obj.self = obj
console.log(Formatter.format(obj))
// {"name":"loop","self":[Circular]}
format(l: Literal(parameter) l: {
_tag: "Literal";
annotations: Schema.Annotations.Annotations | undefined;
literal: string | number | boolean | bigint;
}
l.Literal.literal: string | number | bigint | booleanliteral))
if (const literals: string[]literals.Array<T>.length: numberGets or sets the length of the array. This is a number one higher than the highest index in the array.
length === 1) {
return function makeCode(
runtime: string,
Type: string
): Code
Constructs a
Code
value from a runtime expression string and a
TypeScript type string.
makeCode(`Schema.Literal(${const literals: string[]literals[0]})`, const literals: string[]literals[0])
}
return function makeCode(
runtime: string,
Type: string
): Code
Constructs a
Code
value from a runtime expression string and a
TypeScript type string.
makeCode(`Schema.Literals([${const literals: string[]literals.Array<string>.join(separator?: string): stringAdds all the elements of an array into a string, separated by the specified separator string.
join(", ")}])`, const literals: string[]literals.Array<string>.join(separator?: string): stringAdds all the elements of an array into a string, separated by the specified separator string.
join(" | "))
}
const const mode: "" | ', { mode: "oneOf" }'mode = s: Representation(parameter) s: {
_tag: "Union";
annotations: Schema.Annotations.Annotations | undefined;
types: ReadonlyArray<Representation>;
mode: "anyOf" | "oneOf";
}
s.Union.mode: "anyOf" | "oneOf"mode === "anyOf" ? "" : `, { mode: "oneOf" }`
const const types: Array<Code>types = s: Representation(parameter) s: {
_tag: "Union";
annotations: Schema.Annotations.Annotations | undefined;
types: ReadonlyArray<Representation>;
mode: "anyOf" | "oneOf";
}
s.Union.types: ReadonlyArray<Representation>types.ReadonlyArray<Representation>.map<Code>(callbackfn: (value: Representation, index: number, array: readonly Representation[]) => Code, thisArg?: any): Code[]Calls a defined callback function on each element of an array, and returns an array that contains the results.
map((t: Representationt) => function (local function) recur(s: Representation): Coderecur(t: Representationt))
return function makeCode(
runtime: string,
Type: string
): Code
Constructs a
Code
value from a runtime expression string and a
TypeScript type string.
makeCode(
`Schema.Union([${const types: Array<Code>types.Array<Code>.map<string>(callbackfn: (value: Code, index: number, array: Code[]) => string, thisArg?: any): string[]Calls a defined callback function on each element of an array, and returns an array that contains the results.
map((t: Code(parameter) t: {
runtime: string;
Type: string;
}
t) => t: Code(parameter) t: {
runtime: string;
Type: string;
}
t.runtime: stringruntime).Array<string>.join(separator?: string): stringAdds all the elements of an array into a string, separated by the specified separator string.
join(", ")}]${const mode: "" | ', { mode: "oneOf" }'mode})`,
const types: Array<Code>types.Array<Code>.map<string>(callbackfn: (value: Code, index: number, array: Code[]) => string, thisArg?: any): string[]Calls a defined callback function on each element of an array, and returns an array that contains the results.
map((t: Code(parameter) t: {
runtime: string;
Type: string;
}
t) => t: Code(parameter) t: {
runtime: string;
Type: string;
}
t.type Type: stringType).Array<string>.join(separator?: string): stringAdds all the elements of an array into a string, separated by the specified separator string.
join(" | ")
)
}
}
}
function function (local function) toTypeBrand(annotations: Schema.Annotations.Annotations | undefined): stringtoTypeBrand(annotations: | Schema.Annotations.Annotations
| undefined
annotations: import SchemaSchema.Annotations.interface Annotations.AnnotationsThis interface is used to define the annotations that can be attached to a
schema. You can extend this interface to define your own annotations.
Details
Note that both a missing key or undefined is used to indicate that the
annotation is not present.
This means that can remove any annotation by setting it to undefined.
Example (Defining your own annotations)
import { Schema } from "effect"
// Extend the Annotations interface with a custom `version` annotation
declare module "effect/Schema" {
namespace Annotations {
interface Annotations {
readonly version?:
| readonly [major: number, minor: number, patch: number]
| undefined
}
}
}
// The `version` annotation is now recognized by the TypeScript compiler
const schema = Schema.String.annotate({ version: [1, 2, 0] })
// const version: readonly [major: number, minor: number, patch: number] | undefined
const version = Schema.resolveAnnotations(schema)?.["version"]
if (version) {
// Access individual parts of the version
console.log(version[1])
// Output: 2
}
Annotations | undefined): string {
const const brands: readonly string[]brands = function collectBrands(annotations: Schema.Annotations.Annotations | undefined): ReadonlyArray<string>collectBrands(annotations: | Schema.Annotations.Annotations
| undefined
annotations)
if (const brands: readonly string[]brands.ReadonlyArray<T>.length: numberGets the length of the array. This is a number one higher than the highest element defined in an array.
length === 0) return ""
function (local function) addImport(importDeclaration: string): voidaddImport(`import type * as Brand from "effect/Brand"`)
return const brands: readonly string[]brands.ReadonlyArray<string>.map<string>(callbackfn: (value: string, index: number, array: readonly string[]) => string, thisArg?: any): string[]Calls a defined callback function on each element of an array, and returns an array that contains the results.
map((b: stringb) => ` & Brand.Brand<${function format(input: unknown, options?: {
readonly space?: number | string | undefined;
readonly ignoreToString?: boolean | undefined;
}): string
Converts any JavaScript value into a human-readable string.
When to use
Use when you need to format arbitrary JavaScript values for debugging,
logging, or error messages.
Details
- Output is not valid JSON; use
formatJson
when you need
parseable JSON.
- Handles
BigInt, Symbol, Set, Map, Date, RegExp, and class
instances that JSON.stringify cannot represent.
- Circular references are shown as
"[Circular]" instead of throwing.
- Primitives: stringified naturally (
null, undefined, 123, true).
Strings are JSON-quoted.
- Objects with a custom
toString (not Object.prototype.toString):
toString() is called unless ignoreToString is true.
- Errors with a
cause: formatted as "<message> (cause: <cause>)".
- Iterables (
Set, Map, etc.): formatted as
ClassName([...elements]).
- Class instances: wrapped as
ClassName({...}).
Redactable values are automatically redacted.
- Arrays/objects with 0–1 entries are inline; larger ones are
pretty-printed when
space is set.
space — indentation unit (number of spaces, or a string like
"\t"). Defaults to 0 (compact).
ignoreToString — skip calling toString(). Defaults to false.
Example (Formatting compact output)
import { Formatter } from "effect"
console.log(Formatter.format({ a: 1, b: [2, 3] }))
// {"a":1,"b":[2,3]}
Example (Pretty-printed output)
import { Formatter } from "effect"
console.log(Formatter.format({ a: 1, b: [2, 3] }, { space: 2 }))
// {
// "a": 1,
// "b": [
// 2,
// 3
// ]
// }
Example (Handling circular references)
import { Formatter } from "effect"
const obj: any = { name: "loop" }
obj.self = obj
console.log(Formatter.format(obj))
// {"name":"loop","self":[Circular]}
format(b: stringb)}>`).Array<string>.join(separator?: string): stringAdds all the elements of an array into a string, separated by the specified separator string.
join("")
}
function function (local function) toTypeChecks(checks: ReadonlyArray<Check<Meta>>): stringtoTypeChecks(checks: ReadonlyArray<Check<Meta>>checks: interface ReadonlyArray<T>ReadonlyArray<type Check<M> = Filter<M> | FilterGroup<M>A validation constraint attached to a type. Either a single
Filter
or a
FilterGroup
combining multiple checks.
Check<type Meta = {
readonly _tag: "isDateValid";
} | {
readonly _tag: "isGreaterThanDate";
readonly exclusiveMinimum: globalThis.Date;
} | {
readonly _tag: "isGreaterThanOrEqualToDate";
readonly minimum: globalThis.Date;
} | {
readonly _tag: "isLessThanDate";
readonly exclusiveMaximum: globalThis.Date;
} | {
readonly _tag: "isLessThanOrEqualToDate";
readonly maximum: globalThis.Date;
} | {
readonly _tag: "isBetweenDate";
readonly minimum: globalThis.Date;
readonly maximum: globalThis.Date;
readonly exclusiveMinimum?: boolean | undefined;
readonly exclusiveMaximum?: boolean | undefined;
} | ... 40 more ... | {
...;
}
Meta>>): string {
return checks: ReadonlyArray<Check<Meta>>checks.ReadonlyArray<Check<Meta>>.map<string>(callbackfn: (value: Check<Meta>, index: number, array: readonly Check<Meta>[]) => string, thisArg?: any): string[]Calls a defined callback function on each element of an array, and returns an array that contains the results.
map((c: Check<Meta>c) => function (local function) toTypeCheck(check: Check<Meta>): stringtoTypeCheck(c: Check<Meta>c)).Array<string>.join(separator?: string): stringAdds all the elements of an array into a string, separated by the specified separator string.
join("")
}
function function (local function) toTypeCheck(check: Check<Meta>): stringtoTypeCheck(check: Check<Meta>check: type Check<M> = Filter<M> | FilterGroup<M>A validation constraint attached to a type. Either a single
Filter
or a
FilterGroup
combining multiple checks.
Check<type Meta = {
readonly _tag: "isDateValid";
} | {
readonly _tag: "isGreaterThanDate";
readonly exclusiveMinimum: globalThis.Date;
} | {
readonly _tag: "isGreaterThanOrEqualToDate";
readonly minimum: globalThis.Date;
} | {
readonly _tag: "isLessThanDate";
readonly exclusiveMaximum: globalThis.Date;
} | {
readonly _tag: "isLessThanOrEqualToDate";
readonly maximum: globalThis.Date;
} | {
readonly _tag: "isBetweenDate";
readonly minimum: globalThis.Date;
readonly maximum: globalThis.Date;
readonly exclusiveMinimum?: boolean | undefined;
readonly exclusiveMaximum?: boolean | undefined;
} | ... 40 more ... | {
...;
}
Meta>): string {
switch (check: Check<Meta>check._tag: "Filter" | "FilterGroup"_tag) {
case "Filter":
return function (local function) toTypeBrand(annotations: Schema.Annotations.Annotations | undefined): stringtoTypeBrand(check: Check<Meta>(parameter) check: {
_tag: "Filter";
annotations: Schema.Annotations.Filter | undefined;
meta: M;
}
check.Filter<M>.annotations?: Schema.Annotations.Filter | undefinedannotations)
case "FilterGroup": {
return function (local function) toTypeChecks(checks: ReadonlyArray<Check<Meta>>): stringtoTypeChecks(check: Check<Meta>(parameter) check: {
_tag: "FilterGroup";
annotations: Schema.Annotations.Filter | undefined;
checks: readonly [Check<M>, ...Array<Check<M>>];
}
check.FilterGroup<Meta>.checks: readonly [Check<M>, ...Array<Check<M>>](property) FilterGroup<Meta>.checks: {
0: Check<Meta>;
length: number;
toString: () => string;
toLocaleString: { (): string; (locales: string | string[], options?: Intl.NumberFormatOptions & Intl.DateTimeFormatOptions): string };
concat: { (...items: Array<ConcatArray<Check<Meta>>>): Array<Check<Meta>>; (...items: Array<Check<Meta> | ConcatArray<Check<Meta>>>): Array<Check<Meta>> };
join: (separator?: string) => string;
slice: (start?: number, end?: number) => Array<Check<Meta>>;
indexOf: (searchElement: Check<Meta>, fromIndex?: number) => number;
lastIndexOf: (searchElement: Check<Meta>, fromIndex?: number) => number;
every: { (predicate: (value: Check<Meta>, index: number, array: ReadonlyArray<Check<Meta>>) => value is S, thisArg?: any): this is readonly S[]; (predicate: (value: Check<Meta>, index: number, array: ReadonlyArray<Check<Meta>>) => unknown, thisAr…;
some: (predicate: (value: Check<Meta>, index: number, array: ReadonlyArray<Check<Meta>>) => unknown, thisArg?: any) => boolean;
forEach: (callbackfn: (value: Check<Meta>, index: number, array: ReadonlyArray<Check<Meta>>) => void, thisArg?: any) => void;
map: (callbackfn: (value: Check<Meta>, index: number, array: ReadonlyArray<Check<Meta>>) => U, thisArg?: any) => Array<U>;
filter: { (predicate: (value: Check<Meta>, index: number, array: ReadonlyArray<Check<Meta>>) => value is S, thisArg?: any): Array<S>; (predicate: (value: Check<Meta>, index: number, array: ReadonlyArray<Check<Meta>>) => unknown, thisArg?: any): Ar…;
reduce: { (callbackfn: (previousValue: Check<Meta>, currentValue: Check<Meta>, currentIndex: number, array: ReadonlyArray<Check<Meta>>) => Check<Meta>): Check<Meta>; (callbackfn: (previousValue: Check<Meta>, currentValue: Check<Meta>, currentIndex…;
reduceRight: { (callbackfn: (previousValue: Check<Meta>, currentValue: Check<Meta>, currentIndex: number, array: ReadonlyArray<Check<Meta>>) => Check<Meta>): Check<Meta>; (callbackfn: (previousValue: Check<Meta>, currentValue: Check<Meta>, currentIndex…;
find: { (predicate: (value: Check<Meta>, index: number, obj: ReadonlyArray<Check<Meta>>) => value is S, thisArg?: any): S | undefined; (predicate: (value: Check<Meta>, index: number, obj: ReadonlyArray<Check<Meta>>) => unknown, thisArg?: any): C…;
findIndex: (predicate: (value: Check<Meta>, index: number, obj: ReadonlyArray<Check<Meta>>) => unknown, thisArg?: any) => number;
entries: () => ArrayIterator<[number, Check<Meta>]>;
keys: () => ArrayIterator<number>;
values: () => ArrayIterator<Check<Meta>>;
includes: (searchElement: Check<Meta>, fromIndex?: number) => boolean;
flatMap: (callback: (this: This, value: Check<Meta>, index: number, array: Array<Check<Meta>>) => U | ReadonlyArray<U>, thisArg?: This | undefined) => Array<U>;
flat: (this: A, depth?: D | undefined) => Array<FlatArray<A, D>>;
at: (index: number) => Check<Meta> | undefined;
findLast: { (predicate: (value: Check<Meta>, index: number, array: ReadonlyArray<Check<Meta>>) => value is S, thisArg?: any): S | undefined; (predicate: (value: Check<Meta>, index: number, array: ReadonlyArray<Check<Meta>>) => unknown, thisArg?: any…;
findLastIndex: (predicate: (value: Check<Meta>, index: number, array: ReadonlyArray<Check<Meta>>) => unknown, thisArg?: any) => number;
toReversed: () => Array<Check<Meta>>;
toSorted: (compareFn?: ((a: Check<Meta>, b: Check<Meta>) => number) | undefined) => Array<Check<Meta>>;
toSpliced: { (start: number, deleteCount: number, ...items: Array<Check<Meta>>): Array<Check<Meta>>; (start: number, deleteCount?: number): Array<Check<Meta>> };
with: (index: number, value: Check<Meta>) => Array<Check<Meta>>;
}
checks)
}
}
}
function function (local function) toRuntimeChecks(checks: ReadonlyArray<Check<Meta>>): stringtoRuntimeChecks(checks: ReadonlyArray<Check<Meta>>checks: interface ReadonlyArray<T>ReadonlyArray<type Check<M> = Filter<M> | FilterGroup<M>A validation constraint attached to a type. Either a single
Filter
or a
FilterGroup
combining multiple checks.
Check<type Meta = {
readonly _tag: "isDateValid";
} | {
readonly _tag: "isGreaterThanDate";
readonly exclusiveMinimum: globalThis.Date;
} | {
readonly _tag: "isGreaterThanOrEqualToDate";
readonly minimum: globalThis.Date;
} | {
readonly _tag: "isLessThanDate";
readonly exclusiveMaximum: globalThis.Date;
} | {
readonly _tag: "isLessThanOrEqualToDate";
readonly maximum: globalThis.Date;
} | {
readonly _tag: "isBetweenDate";
readonly minimum: globalThis.Date;
readonly maximum: globalThis.Date;
readonly exclusiveMinimum?: boolean | undefined;
readonly exclusiveMaximum?: boolean | undefined;
} | ... 40 more ... | {
...;
}
Meta>>): string {
return checks: ReadonlyArray<Check<Meta>>checks.ReadonlyArray<Check<Meta>>.map<string>(callbackfn: (value: Check<Meta>, index: number, array: readonly Check<Meta>[]) => string, thisArg?: any): string[]Calls a defined callback function on each element of an array, and returns an array that contains the results.
map((c: Check<Meta>c) => `.check(${function (local function) toRuntimeCheck(check: Check<Meta>): stringtoRuntimeCheck(c: Check<Meta>c)})` + function toRuntimeBrand(
annotations:
| Schema.Annotations.Annotations
| undefined
): string
toRuntimeBrand(c: Check<Meta>c.annotations?: Schema.Annotations.Filter | undefinedannotations)).Array<string>.join(separator?: string): stringAdds all the elements of an array into a string, separated by the specified separator string.
join("")
}
function function (local function) toRuntimeCheck(check: Check<Meta>): stringtoRuntimeCheck(check: Check<Meta>check: type Check<M> = Filter<M> | FilterGroup<M>A validation constraint attached to a type. Either a single
Filter
or a
FilterGroup
combining multiple checks.
Check<type Meta = {
readonly _tag: "isDateValid";
} | {
readonly _tag: "isGreaterThanDate";
readonly exclusiveMinimum: globalThis.Date;
} | {
readonly _tag: "isGreaterThanOrEqualToDate";
readonly minimum: globalThis.Date;
} | {
readonly _tag: "isLessThanDate";
readonly exclusiveMaximum: globalThis.Date;
} | {
readonly _tag: "isLessThanOrEqualToDate";
readonly maximum: globalThis.Date;
} | {
readonly _tag: "isBetweenDate";
readonly minimum: globalThis.Date;
readonly maximum: globalThis.Date;
readonly exclusiveMinimum?: boolean | undefined;
readonly exclusiveMaximum?: boolean | undefined;
} | ... 40 more ... | {
...;
}
Meta>): string {
switch (check: Check<Meta>check._tag: "Filter" | "FilterGroup"_tag) {
case "Filter":
return function (local function) toRuntimeFilter(filter: Filter<Meta>): stringtoRuntimeFilter(check: Check<Meta>(parameter) check: {
_tag: "Filter";
annotations: Schema.Annotations.Filter | undefined;
meta: M;
}
check)
case "FilterGroup": {
const const a: stringa = function toRuntimeAnnotations(
annotations:
| Schema.Annotations.Annotations
| undefined
): string
toRuntimeAnnotations(check: Check<Meta>(parameter) check: {
_tag: "FilterGroup";
annotations: Schema.Annotations.Filter | undefined;
checks: readonly [Check<M>, ...Array<Check<M>>];
}
check.FilterGroup<M>.annotations?: Schema.Annotations.Filter | undefinedannotations)
const const ca: stringca = const a: stringa === "" ? "" : `, ${const a: stringa}`
return `Schema.makeFilterGroup([${check: Check<Meta>(parameter) check: {
_tag: "FilterGroup";
annotations: Schema.Annotations.Filter | undefined;
checks: readonly [Check<M>, ...Array<Check<M>>];
}
check.FilterGroup<Meta>.checks: readonly [Check<M>, ...Array<Check<M>>](property) FilterGroup<Meta>.checks: {
0: Check<Meta>;
length: number;
toString: () => string;
toLocaleString: { (): string; (locales: string | string[], options?: Intl.NumberFormatOptions & Intl.DateTimeFormatOptions): string };
concat: { (...items: Array<ConcatArray<Check<Meta>>>): Array<Check<Meta>>; (...items: Array<Check<Meta> | ConcatArray<Check<Meta>>>): Array<Check<Meta>> };
join: (separator?: string) => string;
slice: (start?: number, end?: number) => Array<Check<Meta>>;
indexOf: (searchElement: Check<Meta>, fromIndex?: number) => number;
lastIndexOf: (searchElement: Check<Meta>, fromIndex?: number) => number;
every: { (predicate: (value: Check<Meta>, index: number, array: ReadonlyArray<Check<Meta>>) => value is S, thisArg?: any): this is readonly S[]; (predicate: (value: Check<Meta>, index: number, array: ReadonlyArray<Check<Meta>>) => unknown, thisAr…;
some: (predicate: (value: Check<Meta>, index: number, array: ReadonlyArray<Check<Meta>>) => unknown, thisArg?: any) => boolean;
forEach: (callbackfn: (value: Check<Meta>, index: number, array: ReadonlyArray<Check<Meta>>) => void, thisArg?: any) => void;
map: (callbackfn: (value: Check<Meta>, index: number, array: ReadonlyArray<Check<Meta>>) => U, thisArg?: any) => Array<U>;
filter: { (predicate: (value: Check<Meta>, index: number, array: ReadonlyArray<Check<Meta>>) => value is S, thisArg?: any): Array<S>; (predicate: (value: Check<Meta>, index: number, array: ReadonlyArray<Check<Meta>>) => unknown, thisArg?: any): Ar…;
reduce: { (callbackfn: (previousValue: Check<Meta>, currentValue: Check<Meta>, currentIndex: number, array: ReadonlyArray<Check<Meta>>) => Check<Meta>): Check<Meta>; (callbackfn: (previousValue: Check<Meta>, currentValue: Check<Meta>, currentIndex…;
reduceRight: { (callbackfn: (previousValue: Check<Meta>, currentValue: Check<Meta>, currentIndex: number, array: ReadonlyArray<Check<Meta>>) => Check<Meta>): Check<Meta>; (callbackfn: (previousValue: Check<Meta>, currentValue: Check<Meta>, currentIndex…;
find: { (predicate: (value: Check<Meta>, index: number, obj: ReadonlyArray<Check<Meta>>) => value is S, thisArg?: any): S | undefined; (predicate: (value: Check<Meta>, index: number, obj: ReadonlyArray<Check<Meta>>) => unknown, thisArg?: any): C…;
findIndex: (predicate: (value: Check<Meta>, index: number, obj: ReadonlyArray<Check<Meta>>) => unknown, thisArg?: any) => number;
entries: () => ArrayIterator<[number, Check<Meta>]>;
keys: () => ArrayIterator<number>;
values: () => ArrayIterator<Check<Meta>>;
includes: (searchElement: Check<Meta>, fromIndex?: number) => boolean;
flatMap: (callback: (this: This, value: Check<Meta>, index: number, array: Array<Check<Meta>>) => U | ReadonlyArray<U>, thisArg?: This | undefined) => Array<U>;
flat: (this: A, depth?: D | undefined) => Array<FlatArray<A, D>>;
at: (index: number) => Check<Meta> | undefined;
findLast: { (predicate: (value: Check<Meta>, index: number, array: ReadonlyArray<Check<Meta>>) => value is S, thisArg?: any): S | undefined; (predicate: (value: Check<Meta>, index: number, array: ReadonlyArray<Check<Meta>>) => unknown, thisArg?: any…;
findLastIndex: (predicate: (value: Check<Meta>, index: number, array: ReadonlyArray<Check<Meta>>) => unknown, thisArg?: any) => number;
toReversed: () => Array<Check<Meta>>;
toSorted: (compareFn?: ((a: Check<Meta>, b: Check<Meta>) => number) | undefined) => Array<Check<Meta>>;
toSpliced: { (start: number, deleteCount: number, ...items: Array<Check<Meta>>): Array<Check<Meta>>; (start: number, deleteCount?: number): Array<Check<Meta>> };
with: (index: number, value: Check<Meta>) => Array<Check<Meta>>;
}
checks.ReadonlyArray<Check<Meta>>.map<string>(callbackfn: (value: Check<Meta>, index: number, array: readonly Check<Meta>[]) => string, thisArg?: any): string[]Calls a defined callback function on each element of an array, and returns an array that contains the results.
map((c: Check<Meta>c) => function (local function) toRuntimeCheck(check: Check<Meta>): stringtoRuntimeCheck(c: Check<Meta>c)).Array<string>.join(separator?: string): stringAdds all the elements of an array into a string, separated by the specified separator string.
join(", ")}]${const ca: stringca})`
}
}
}
function function (local function) toRuntimeFilter(filter: Filter<Meta>): stringtoRuntimeFilter(filter: Filter<Meta>(parameter) filter: {
_tag: "Filter";
annotations: Schema.Annotations.Filter | undefined;
meta: M;
}
filter: interface Filter<M>A single validation constraint with typed metadata describing the check
(e.g. { _tag: "isMinLength", minLength: 3 }).
Filter<type Meta = {
readonly _tag: "isDateValid";
} | {
readonly _tag: "isGreaterThanDate";
readonly exclusiveMinimum: globalThis.Date;
} | {
readonly _tag: "isGreaterThanOrEqualToDate";
readonly minimum: globalThis.Date;
} | {
readonly _tag: "isLessThanDate";
readonly exclusiveMaximum: globalThis.Date;
} | {
readonly _tag: "isLessThanOrEqualToDate";
readonly maximum: globalThis.Date;
} | {
readonly _tag: "isBetweenDate";
readonly minimum: globalThis.Date;
readonly maximum: globalThis.Date;
readonly exclusiveMinimum?: boolean | undefined;
readonly exclusiveMaximum?: boolean | undefined;
} | ... 40 more ... | {
...;
}
Meta>): string {
const const a: stringa = function toRuntimeAnnotations(
annotations:
| Schema.Annotations.Annotations
| undefined
): string
toRuntimeAnnotations(filter: Filter<Meta>(parameter) filter: {
_tag: "Filter";
annotations: Schema.Annotations.Filter | undefined;
meta: M;
}
filter.Filter<M>.annotations?: Schema.Annotations.Filter | undefinedannotations)
const const ca: stringca = const a: stringa === "" ? "" : `, ${const a: stringa}`
switch (filter: Filter<Meta>(parameter) filter: {
_tag: "Filter";
annotations: Schema.Annotations.Filter | undefined;
meta: M;
}
filter.Filter<Meta>.meta: Metameta._tag: "isDateValid" | "isGreaterThanDate" | "isGreaterThanOrEqualToDate" | "isLessThanDate" | "isLessThanOrEqualToDate" | "isBetweenDate" | "isMinSize" | "isMaxSize" | "isSizeBetween" | "isStringFinite" | "isStringBigInt" | "isStringSymbol" | "isMinLength" | "isMaxLength" | "isPattern" | "isLengthBetween" | "isTrimmed" | "isUUID" | "isGUID" | "isULID" | "isBase64" | "isBase64Url" | "isStartsWith" | "isEndsWith" | "isIncludes" | "isUppercased" | "isLowercased" | "isCapitalized" | "isUncapitalized" | "isInt" | "isFinite" | "isMultipleOf" | ... 14 more ... | "isPropertyNames"_tag) {
case "isTrimmed":
case "isGUID":
case "isULID":
case "isBase64":
case "isBase64Url":
case "isUppercased":
case "isLowercased":
case "isCapitalized":
case "isUncapitalized":
case "isFinite":
case "isInt":
case "isUnique":
case "isDateValid":
return `Schema.${filter: Filter<Meta>(parameter) filter: {
_tag: "Filter";
annotations: Schema.Annotations.Filter | undefined;
meta: M;
}
filter.Filter<Meta>.meta: {
readonly _tag: "isDateValid";
} | {
readonly _tag: "isTrimmed";
readonly regExp: globalThis.RegExp;
} | {
readonly _tag: "isGUID";
readonly regExp: globalThis.RegExp;
} | {
readonly _tag: "isULID";
readonly regExp: globalThis.RegExp;
} | {
readonly _tag: "isBase64";
readonly regExp: globalThis.RegExp;
} | {
readonly _tag: "isBase64Url";
readonly regExp: globalThis.RegExp;
} | {
readonly _tag: "isUppercased";
readonly regExp: globalThis.RegExp;
} | {
readonly _tag: "isLowercased";
readonly regExp: globalThis.RegExp;
} | {
readonly _tag: "isCapitalized";
readonly regExp: globalThis.RegExp;
} | {
...;
} | {
...;
} | {
...;
} | {
...;
}
meta._tag: | "isDateValid"
| "isTrimmed"
| "isGUID"
| "isULID"
| "isBase64"
| "isBase64Url"
| "isUppercased"
| "isLowercased"
| "isCapitalized"
| "isUncapitalized"
| "isInt"
| "isFinite"
| "isUnique"
_tag}(${const a: stringa})`
case "isStringFinite":
case "isStringBigInt":
case "isStringSymbol":
case "isPattern":
return `Schema.${filter: Filter<Meta>(parameter) filter: {
_tag: "Filter";
annotations: Schema.Annotations.Filter | undefined;
meta: M;
}
filter.Filter<Meta>.meta: {
readonly _tag: "isStringFinite";
readonly regExp: globalThis.RegExp;
} | {
readonly _tag: "isStringBigInt";
readonly regExp: globalThis.RegExp;
} | {
readonly _tag: "isStringSymbol";
readonly regExp: globalThis.RegExp;
} | {
readonly _tag: "isPattern";
readonly regExp: globalThis.RegExp;
}
meta._tag: | "isStringFinite"
| "isStringBigInt"
| "isStringSymbol"
| "isPattern"
_tag}(${function toRuntimeRegExp(
regExp: RegExp
): string
toRuntimeRegExp(filter: Filter<Meta>(parameter) filter: {
_tag: "Filter";
annotations: Schema.Annotations.Filter | undefined;
meta: M;
}
filter.Filter<Meta>.meta: {
readonly _tag: "isStringFinite";
readonly regExp: globalThis.RegExp;
} | {
readonly _tag: "isStringBigInt";
readonly regExp: globalThis.RegExp;
} | {
readonly _tag: "isStringSymbol";
readonly regExp: globalThis.RegExp;
} | {
readonly _tag: "isPattern";
readonly regExp: globalThis.RegExp;
}
meta.regExp: RegExpregExp)}${const ca: stringca})`
case "isMinLength":
return `Schema.isMinLength(${filter: Filter<Meta>(parameter) filter: {
_tag: "Filter";
annotations: Schema.Annotations.Filter | undefined;
meta: M;
}
filter.Filter<Meta>.meta: {
readonly _tag: "isMinLength";
readonly minLength: number;
}
meta.minLength: numberminLength}${const ca: stringca})`
case "isMaxLength":
return `Schema.isMaxLength(${filter: Filter<Meta>(parameter) filter: {
_tag: "Filter";
annotations: Schema.Annotations.Filter | undefined;
meta: M;
}
filter.Filter<Meta>.meta: {
readonly _tag: "isMaxLength";
readonly maxLength: number;
}
meta.maxLength: numbermaxLength}${const ca: stringca})`
case "isLengthBetween":
return `Schema.isLengthBetween(${filter: Filter<Meta>(parameter) filter: {
_tag: "Filter";
annotations: Schema.Annotations.Filter | undefined;
meta: M;
}
filter.Filter<Meta>.meta: {
readonly _tag: "isLengthBetween";
readonly minimum: number;
readonly maximum: number;
}
meta.minimum: numberminimum}, ${filter: Filter<Meta>(parameter) filter: {
_tag: "Filter";
annotations: Schema.Annotations.Filter | undefined;
meta: M;
}
filter.Filter<Meta>.meta: {
readonly _tag: "isLengthBetween";
readonly minimum: number;
readonly maximum: number;
}
meta.maximum: numbermaximum}${const ca: stringca})`
case "isUUID":
return `Schema.isUUID(${filter: Filter<Meta>(parameter) filter: {
_tag: "Filter";
annotations: Schema.Annotations.Filter | undefined;
meta: M;
}
filter.Filter<Meta>.meta: {
readonly _tag: "isUUID";
readonly regExp: globalThis.RegExp;
readonly version: 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | undefined;
}
meta.version: | 2
| 1
| 3
| 6
| 4
| 5
| 7
| 8
| undefined
version}${const ca: stringca})`
case "isStartsWith":
return `Schema.isStartsWith(${function format(input: unknown, options?: {
readonly space?: number | string | undefined;
readonly ignoreToString?: boolean | undefined;
}): string
Converts any JavaScript value into a human-readable string.
When to use
Use when you need to format arbitrary JavaScript values for debugging,
logging, or error messages.
Details
- Output is not valid JSON; use
formatJson
when you need
parseable JSON.
- Handles
BigInt, Symbol, Set, Map, Date, RegExp, and class
instances that JSON.stringify cannot represent.
- Circular references are shown as
"[Circular]" instead of throwing.
- Primitives: stringified naturally (
null, undefined, 123, true).
Strings are JSON-quoted.
- Objects with a custom
toString (not Object.prototype.toString):
toString() is called unless ignoreToString is true.
- Errors with a
cause: formatted as "<message> (cause: <cause>)".
- Iterables (
Set, Map, etc.): formatted as
ClassName([...elements]).
- Class instances: wrapped as
ClassName({...}).
Redactable values are automatically redacted.
- Arrays/objects with 0–1 entries are inline; larger ones are
pretty-printed when
space is set.
space — indentation unit (number of spaces, or a string like
"\t"). Defaults to 0 (compact).
ignoreToString — skip calling toString(). Defaults to false.
Example (Formatting compact output)
import { Formatter } from "effect"
console.log(Formatter.format({ a: 1, b: [2, 3] }))
// {"a":1,"b":[2,3]}
Example (Pretty-printed output)
import { Formatter } from "effect"
console.log(Formatter.format({ a: 1, b: [2, 3] }, { space: 2 }))
// {
// "a": 1,
// "b": [
// 2,
// 3
// ]
// }
Example (Handling circular references)
import { Formatter } from "effect"
const obj: any = { name: "loop" }
obj.self = obj
console.log(Formatter.format(obj))
// {"name":"loop","self":[Circular]}
format(filter: Filter<Meta>(parameter) filter: {
_tag: "Filter";
annotations: Schema.Annotations.Filter | undefined;
meta: M;
}
filter.Filter<Meta>.meta: {
readonly _tag: "isStartsWith";
readonly startsWith: string;
readonly regExp: globalThis.RegExp;
}
meta.startsWith: stringstartsWith)}${const ca: stringca})`
case "isEndsWith":
return `Schema.isEndsWith(${function format(input: unknown, options?: {
readonly space?: number | string | undefined;
readonly ignoreToString?: boolean | undefined;
}): string
Converts any JavaScript value into a human-readable string.
When to use
Use when you need to format arbitrary JavaScript values for debugging,
logging, or error messages.
Details
- Output is not valid JSON; use
formatJson
when you need
parseable JSON.
- Handles
BigInt, Symbol, Set, Map, Date, RegExp, and class
instances that JSON.stringify cannot represent.
- Circular references are shown as
"[Circular]" instead of throwing.
- Primitives: stringified naturally (
null, undefined, 123, true).
Strings are JSON-quoted.
- Objects with a custom
toString (not Object.prototype.toString):
toString() is called unless ignoreToString is true.
- Errors with a
cause: formatted as "<message> (cause: <cause>)".
- Iterables (
Set, Map, etc.): formatted as
ClassName([...elements]).
- Class instances: wrapped as
ClassName({...}).
Redactable values are automatically redacted.
- Arrays/objects with 0–1 entries are inline; larger ones are
pretty-printed when
space is set.
space — indentation unit (number of spaces, or a string like
"\t"). Defaults to 0 (compact).
ignoreToString — skip calling toString(). Defaults to false.
Example (Formatting compact output)
import { Formatter } from "effect"
console.log(Formatter.format({ a: 1, b: [2, 3] }))
// {"a":1,"b":[2,3]}
Example (Pretty-printed output)
import { Formatter } from "effect"
console.log(Formatter.format({ a: 1, b: [2, 3] }, { space: 2 }))
// {
// "a": 1,
// "b": [
// 2,
// 3
// ]
// }
Example (Handling circular references)
import { Formatter } from "effect"
const obj: any = { name: "loop" }
obj.self = obj
console.log(Formatter.format(obj))
// {"name":"loop","self":[Circular]}
format(filter: Filter<Meta>(parameter) filter: {
_tag: "Filter";
annotations: Schema.Annotations.Filter | undefined;
meta: M;
}
filter.Filter<Meta>.meta: {
readonly _tag: "isEndsWith";
readonly endsWith: string;
readonly regExp: globalThis.RegExp;
}
meta.endsWith: stringendsWith)}${const ca: stringca})`
case "isIncludes":
return `Schema.isIncludes(${function format(input: unknown, options?: {
readonly space?: number | string | undefined;
readonly ignoreToString?: boolean | undefined;
}): string
Converts any JavaScript value into a human-readable string.
When to use
Use when you need to format arbitrary JavaScript values for debugging,
logging, or error messages.
Details
- Output is not valid JSON; use
formatJson
when you need
parseable JSON.
- Handles
BigInt, Symbol, Set, Map, Date, RegExp, and class
instances that JSON.stringify cannot represent.
- Circular references are shown as
"[Circular]" instead of throwing.
- Primitives: stringified naturally (
null, undefined, 123, true).
Strings are JSON-quoted.
- Objects with a custom
toString (not Object.prototype.toString):
toString() is called unless ignoreToString is true.
- Errors with a
cause: formatted as "<message> (cause: <cause>)".
- Iterables (
Set, Map, etc.): formatted as
ClassName([...elements]).
- Class instances: wrapped as
ClassName({...}).
Redactable values are automatically redacted.
- Arrays/objects with 0–1 entries are inline; larger ones are
pretty-printed when
space is set.
space — indentation unit (number of spaces, or a string like
"\t"). Defaults to 0 (compact).
ignoreToString — skip calling toString(). Defaults to false.
Example (Formatting compact output)
import { Formatter } from "effect"
console.log(Formatter.format({ a: 1, b: [2, 3] }))
// {"a":1,"b":[2,3]}
Example (Pretty-printed output)
import { Formatter } from "effect"
console.log(Formatter.format({ a: 1, b: [2, 3] }, { space: 2 }))
// {
// "a": 1,
// "b": [
// 2,
// 3
// ]
// }
Example (Handling circular references)
import { Formatter } from "effect"
const obj: any = { name: "loop" }
obj.self = obj
console.log(Formatter.format(obj))
// {"name":"loop","self":[Circular]}
format(filter: Filter<Meta>(parameter) filter: {
_tag: "Filter";
annotations: Schema.Annotations.Filter | undefined;
meta: M;
}
filter.Filter<Meta>.meta: {
readonly _tag: "isIncludes";
readonly includes: string;
readonly regExp: globalThis.RegExp;
}
meta.includes: stringincludes)}${const ca: stringca})`
case "isGreaterThan":
case "isGreaterThanBigInt":
case "isGreaterThanDate":
return `Schema.${filter: Filter<Meta>(parameter) filter: {
_tag: "Filter";
annotations: Schema.Annotations.Filter | undefined;
meta: M;
}
filter.Filter<Meta>.meta: {
readonly _tag: "isGreaterThanDate";
readonly exclusiveMinimum: globalThis.Date;
} | {
readonly _tag: "isGreaterThan";
readonly exclusiveMinimum: number;
} | {
readonly _tag: "isGreaterThanBigInt";
readonly exclusiveMinimum: bigint;
}
meta._tag: | "isGreaterThanDate"
| "isGreaterThan"
| "isGreaterThanBigInt"
_tag}(${function toRuntimeValue(
value:
| undefined
| number
| boolean
| bigint
| Date
): string
toRuntimeValue(filter: Filter<Meta>(parameter) filter: {
_tag: "Filter";
annotations: Schema.Annotations.Filter | undefined;
meta: M;
}
filter.Filter<Meta>.meta: {
readonly _tag: "isGreaterThanDate";
readonly exclusiveMinimum: globalThis.Date;
} | {
readonly _tag: "isGreaterThan";
readonly exclusiveMinimum: number;
} | {
readonly _tag: "isGreaterThanBigInt";
readonly exclusiveMinimum: bigint;
}
meta.exclusiveMinimum: number | bigint | DateexclusiveMinimum)}${const ca: stringca})`
case "isGreaterThanOrEqualTo":
case "isGreaterThanOrEqualToBigInt":
case "isGreaterThanOrEqualToDate":
return `Schema.${filter: Filter<Meta>(parameter) filter: {
_tag: "Filter";
annotations: Schema.Annotations.Filter | undefined;
meta: M;
}
filter.Filter<Meta>.meta: {
readonly _tag: "isGreaterThanOrEqualToDate";
readonly minimum: globalThis.Date;
} | {
readonly _tag: "isGreaterThanOrEqualTo";
readonly minimum: number;
} | {
readonly _tag: "isGreaterThanOrEqualToBigInt";
readonly minimum: bigint;
}
meta._tag: | "isGreaterThanOrEqualToDate"
| "isGreaterThanOrEqualTo"
| "isGreaterThanOrEqualToBigInt"
_tag}(${function toRuntimeValue(
value:
| undefined
| number
| boolean
| bigint
| Date
): string
toRuntimeValue(filter: Filter<Meta>(parameter) filter: {
_tag: "Filter";
annotations: Schema.Annotations.Filter | undefined;
meta: M;
}
filter.Filter<Meta>.meta: {
readonly _tag: "isGreaterThanOrEqualToDate";
readonly minimum: globalThis.Date;
} | {
readonly _tag: "isGreaterThanOrEqualTo";
readonly minimum: number;
} | {
readonly _tag: "isGreaterThanOrEqualToBigInt";
readonly minimum: bigint;
}
meta.minimum: number | bigint | Dateminimum)}${const ca: stringca})`
case "isLessThan":
case "isLessThanBigInt":
case "isLessThanDate":
return `Schema.${filter: Filter<Meta>(parameter) filter: {
_tag: "Filter";
annotations: Schema.Annotations.Filter | undefined;
meta: M;
}
filter.Filter<Meta>.meta: {
readonly _tag: "isLessThanDate";
readonly exclusiveMaximum: globalThis.Date;
} | {
readonly _tag: "isLessThan";
readonly exclusiveMaximum: number;
} | {
readonly _tag: "isLessThanBigInt";
readonly exclusiveMaximum: bigint;
}
meta._tag: | "isLessThanDate"
| "isLessThan"
| "isLessThanBigInt"
_tag}(${function toRuntimeValue(
value:
| undefined
| number
| boolean
| bigint
| Date
): string
toRuntimeValue(filter: Filter<Meta>(parameter) filter: {
_tag: "Filter";
annotations: Schema.Annotations.Filter | undefined;
meta: M;
}
filter.Filter<Meta>.meta: {
readonly _tag: "isLessThanDate";
readonly exclusiveMaximum: globalThis.Date;
} | {
readonly _tag: "isLessThan";
readonly exclusiveMaximum: number;
} | {
readonly _tag: "isLessThanBigInt";
readonly exclusiveMaximum: bigint;
}
meta.exclusiveMaximum: number | bigint | DateexclusiveMaximum)}${const ca: stringca})`
case "isLessThanOrEqualTo":
case "isLessThanOrEqualToBigInt":
case "isLessThanOrEqualToDate":
return `Schema.${filter: Filter<Meta>(parameter) filter: {
_tag: "Filter";
annotations: Schema.Annotations.Filter | undefined;
meta: M;
}
filter.Filter<Meta>.meta: {
readonly _tag: "isLessThanOrEqualToDate";
readonly maximum: globalThis.Date;
} | {
readonly _tag: "isLessThanOrEqualTo";
readonly maximum: number;
} | {
readonly _tag: "isLessThanOrEqualToBigInt";
readonly maximum: bigint;
}
meta._tag: | "isLessThanOrEqualToDate"
| "isLessThanOrEqualTo"
| "isLessThanOrEqualToBigInt"
_tag}(${function toRuntimeValue(
value:
| undefined
| number
| boolean
| bigint
| Date
): string
toRuntimeValue(filter: Filter<Meta>(parameter) filter: {
_tag: "Filter";
annotations: Schema.Annotations.Filter | undefined;
meta: M;
}
filter.Filter<Meta>.meta: {
readonly _tag: "isLessThanOrEqualToDate";
readonly maximum: globalThis.Date;
} | {
readonly _tag: "isLessThanOrEqualTo";
readonly maximum: number;
} | {
readonly _tag: "isLessThanOrEqualToBigInt";
readonly maximum: bigint;
}
meta.maximum: number | bigint | Datemaximum)}${const ca: stringca})`
case "isBetween":
case "isBetweenBigInt":
case "isBetweenDate":
return `Schema.${filter: Filter<Meta>(parameter) filter: {
_tag: "Filter";
annotations: Schema.Annotations.Filter | undefined;
meta: M;
}
filter.Filter<Meta>.meta: {
readonly _tag: "isBetweenDate";
readonly minimum: globalThis.Date;
readonly maximum: globalThis.Date;
readonly exclusiveMinimum?: boolean | undefined;
readonly exclusiveMaximum?: boolean | undefined;
} | {
readonly _tag: "isBetween";
readonly minimum: number;
readonly maximum: number;
readonly exclusiveMinimum?: boolean | undefined;
readonly exclusiveMaximum?: boolean | undefined;
} | {
readonly _tag: "isBetweenBigInt";
readonly minimum: bigint;
readonly maximum: bigint;
readonly exclusiveMinimum?: boolean | undefined;
readonly exclusiveMaximum?: boolean | undefined;
}
meta._tag: | "isBetweenDate"
| "isBetween"
| "isBetweenBigInt"
_tag}({ minimum: ${function toRuntimeValue(
value:
| undefined
| number
| boolean
| bigint
| Date
): string
toRuntimeValue(filter: Filter<Meta>(parameter) filter: {
_tag: "Filter";
annotations: Schema.Annotations.Filter | undefined;
meta: M;
}
filter.Filter<Meta>.meta: {
readonly _tag: "isBetweenDate";
readonly minimum: globalThis.Date;
readonly maximum: globalThis.Date;
readonly exclusiveMinimum?: boolean | undefined;
readonly exclusiveMaximum?: boolean | undefined;
} | {
readonly _tag: "isBetween";
readonly minimum: number;
readonly maximum: number;
readonly exclusiveMinimum?: boolean | undefined;
readonly exclusiveMaximum?: boolean | undefined;
} | {
readonly _tag: "isBetweenBigInt";
readonly minimum: bigint;
readonly maximum: bigint;
readonly exclusiveMinimum?: boolean | undefined;
readonly exclusiveMaximum?: boolean | undefined;
}
meta.minimum: number | bigint | Dateminimum)}, maximum: ${
function toRuntimeValue(
value:
| undefined
| number
| boolean
| bigint
| Date
): string
toRuntimeValue(filter: Filter<Meta>(parameter) filter: {
_tag: "Filter";
annotations: Schema.Annotations.Filter | undefined;
meta: M;
}
filter.Filter<Meta>.meta: {
readonly _tag: "isBetweenDate";
readonly minimum: globalThis.Date;
readonly maximum: globalThis.Date;
readonly exclusiveMinimum?: boolean | undefined;
readonly exclusiveMaximum?: boolean | undefined;
} | {
readonly _tag: "isBetween";
readonly minimum: number;
readonly maximum: number;
readonly exclusiveMinimum?: boolean | undefined;
readonly exclusiveMaximum?: boolean | undefined;
} | {
readonly _tag: "isBetweenBigInt";
readonly minimum: bigint;
readonly maximum: bigint;
readonly exclusiveMinimum?: boolean | undefined;
readonly exclusiveMaximum?: boolean | undefined;
}
meta.maximum: number | bigint | Datemaximum)
}, exclusiveMinimum: ${function toRuntimeValue(
value:
| undefined
| number
| boolean
| bigint
| Date
): string
toRuntimeValue(filter: Filter<Meta>(parameter) filter: {
_tag: "Filter";
annotations: Schema.Annotations.Filter | undefined;
meta: M;
}
filter.Filter<Meta>.meta: {
readonly _tag: "isBetweenDate";
readonly minimum: globalThis.Date;
readonly maximum: globalThis.Date;
readonly exclusiveMinimum?: boolean | undefined;
readonly exclusiveMaximum?: boolean | undefined;
} | {
readonly _tag: "isBetween";
readonly minimum: number;
readonly maximum: number;
readonly exclusiveMinimum?: boolean | undefined;
readonly exclusiveMaximum?: boolean | undefined;
} | {
readonly _tag: "isBetweenBigInt";
readonly minimum: bigint;
readonly maximum: bigint;
readonly exclusiveMinimum?: boolean | undefined;
readonly exclusiveMaximum?: boolean | undefined;
}
meta.exclusiveMinimum?: boolean | undefinedexclusiveMinimum)}, exclusiveMaximum: ${
function toRuntimeValue(
value:
| undefined
| number
| boolean
| bigint
| Date
): string
toRuntimeValue(filter: Filter<Meta>(parameter) filter: {
_tag: "Filter";
annotations: Schema.Annotations.Filter | undefined;
meta: M;
}
filter.Filter<Meta>.meta: {
readonly _tag: "isBetweenDate";
readonly minimum: globalThis.Date;
readonly maximum: globalThis.Date;
readonly exclusiveMinimum?: boolean | undefined;
readonly exclusiveMaximum?: boolean | undefined;
} | {
readonly _tag: "isBetween";
readonly minimum: number;
readonly maximum: number;
readonly exclusiveMinimum?: boolean | undefined;
readonly exclusiveMaximum?: boolean | undefined;
} | {
readonly _tag: "isBetweenBigInt";
readonly minimum: bigint;
readonly maximum: bigint;
readonly exclusiveMinimum?: boolean | undefined;
readonly exclusiveMaximum?: boolean | undefined;
}
meta.exclusiveMaximum?: boolean | undefinedexclusiveMaximum)
}${const ca: stringca})`
case "isMultipleOf":
return `Schema.isMultipleOf(${filter: Filter<Meta>(parameter) filter: {
_tag: "Filter";
annotations: Schema.Annotations.Filter | undefined;
meta: M;
}
filter.Filter<Meta>.meta: {
readonly _tag: "isMultipleOf";
readonly divisor: number;
}
meta.divisor: numberdivisor}${const ca: stringca})`
case "isMinProperties":
return `Schema.isMinProperties(${filter: Filter<Meta>(parameter) filter: {
_tag: "Filter";
annotations: Schema.Annotations.Filter | undefined;
meta: M;
}
filter.Filter<Meta>.meta: {
readonly _tag: "isMinProperties";
readonly minProperties: number;
}
meta.minProperties: numberminProperties}${const ca: stringca})`
case "isMaxProperties":
return `Schema.isMaxProperties(${filter: Filter<Meta>(parameter) filter: {
_tag: "Filter";
annotations: Schema.Annotations.Filter | undefined;
meta: M;
}
filter.Filter<Meta>.meta: {
readonly _tag: "isMaxProperties";
readonly maxProperties: number;
}
meta.maxProperties: numbermaxProperties}${const ca: stringca})`
case "isPropertiesLengthBetween":
return `Schema.isPropertiesLengthBetween(${filter: Filter<Meta>(parameter) filter: {
_tag: "Filter";
annotations: Schema.Annotations.Filter | undefined;
meta: M;
}
filter.Filter<Meta>.meta: {
readonly _tag: "isPropertiesLengthBetween";
readonly minimum: number;
readonly maximum: number;
}
meta.minimum: numberminimum}, ${filter: Filter<Meta>(parameter) filter: {
_tag: "Filter";
annotations: Schema.Annotations.Filter | undefined;
meta: M;
}
filter.Filter<Meta>.meta: {
readonly _tag: "isPropertiesLengthBetween";
readonly minimum: number;
readonly maximum: number;
}
meta.maximum: numbermaximum}${const ca: stringca})`
case "isPropertyNames":
return `Schema.isPropertyNames(${function (local function) recur(s: Representation): Coderecur(filter: Filter<Meta>(parameter) filter: {
_tag: "Filter";
annotations: Schema.Annotations.Filter | undefined;
meta: M;
}
filter.Filter<Meta>.meta: {
...;
}
meta.propertyNames: RepresentationpropertyNames).runtime: stringruntime}${const ca: stringca})`
case "isMinSize":
return `Schema.isMinSize(${filter: Filter<Meta>(parameter) filter: {
_tag: "Filter";
annotations: Schema.Annotations.Filter | undefined;
meta: M;
}
filter.Filter<Meta>.meta: {
readonly _tag: "isMinSize";
readonly minSize: number;
}
meta.minSize: numberminSize}${const ca: stringca})`
case "isMaxSize":
return `Schema.isMaxSize(${filter: Filter<Meta>(parameter) filter: {
_tag: "Filter";
annotations: Schema.Annotations.Filter | undefined;
meta: M;
}
filter.Filter<Meta>.meta: {
readonly _tag: "isMaxSize";
readonly maxSize: number;
}
meta.maxSize: numbermaxSize}${const ca: stringca})`
case "isSizeBetween":
return `Schema.isSizeBetween(${filter: Filter<Meta>(parameter) filter: {
_tag: "Filter";
annotations: Schema.Annotations.Filter | undefined;
meta: M;
}
filter.Filter<Meta>.meta: {
readonly _tag: "isSizeBetween";
readonly minimum: number;
readonly maximum: number;
}
meta.minimum: numberminimum}, ${filter: Filter<Meta>(parameter) filter: {
_tag: "Filter";
annotations: Schema.Annotations.Filter | undefined;
meta: M;
}
filter.Filter<Meta>.meta: {
readonly _tag: "isSizeBetween";
readonly minimum: number;
readonly maximum: number;
}
meta.maximum: numbermaximum}${const ca: stringca})`
}
}
}