<S extends Constraint>(
schema: S,
options?: {
readonly onBefore?:
| ((
ast: SchemaAST.AST,
recur: (ast: SchemaAST.AST) => Formatter<any>
) => Formatter<any> | undefined)
| undefined
}
): Formatter<S["Type"]>Derives a string formatter function from a schema. The formatter converts a value to its human-readable string representation, recursing into structs, arrays, and unions.
Details
The optional onBefore hook lets you intercept specific AST nodes before
the default formatting logic runs.
export function function toFormatter<
S extends Constraint
>(
schema: S,
options?: {
readonly onBefore?:
| ((
ast: SchemaAST.AST,
recur: (
ast: SchemaAST.AST
) => Formatter<any>
) => Formatter<any> | undefined)
| undefined
}
): Formatter<S["Type"]>
Derives a string formatter function from a schema. The formatter converts
a value to its human-readable string representation, recursing into structs,
arrays, and unions.
Details
The optional onBefore hook lets you intercept specific AST nodes before
the default formatting logic runs.
toFormatter<function (type parameter) S in toFormatter<S extends Constraint>(schema: S, options?: {
readonly onBefore?: ((ast: SchemaAST.AST, recur: (ast: SchemaAST.AST) => Formatter<any>) => Formatter<any> | undefined) | undefined;
}): Formatter<S["Type"]>
S extends Constraint>(schema: S extends Constraintschema: function (type parameter) S in toFormatter<S extends Constraint>(schema: S, options?: {
readonly onBefore?: ((ast: SchemaAST.AST, recur: (ast: SchemaAST.AST) => Formatter<any>) => Formatter<any> | undefined) | undefined;
}): Formatter<S["Type"]>
S, options: {
readonly onBefore?:
| ((
ast: SchemaAST.AST,
recur: (
ast: SchemaAST.AST
) => Formatter<any>
) => Formatter<any> | undefined)
| undefined
}
options?: {
readonly onBefore?: | ((
ast: SchemaAST.AST,
recur: (
ast: SchemaAST.AST
) => Formatter<any>
) => Formatter<any> | undefined)
| undefined
onBefore?:
| ((ast: SchemaAST.ASTast: import SchemaASTSchemaAST.type AST = SchemaAST.Declaration | SchemaAST.Null | SchemaAST.Undefined | SchemaAST.Void | SchemaAST.Never | SchemaAST.Unknown | SchemaAST.Any | SchemaAST.String | SchemaAST.Number | SchemaAST.Boolean | SchemaAST.BigInt | SchemaAST.Symbol | SchemaAST.Literal | SchemaAST.UniqueSymbol | SchemaAST.ObjectKeyword | SchemaAST.Enum | SchemaAST.TemplateLiteral | SchemaAST.Arrays | SchemaAST.Objects | SchemaAST.Union<...> | SchemaAST.SuspendDiscriminated union of all AST node types.
Details
Every Schema has an .ast property of this type. Use the guard functions
(
isString
,
isObjects
, etc.) to narrow to a specific variant,
then access variant-specific fields.
- All variants share the
Base
fields:
annotations, checks,
encoding, context.
- Discriminate on the
_tag field (e.g. "String", "Objects", "Union").
AST, recur: (ast: SchemaAST.AST) => Formatter<any>recur: (ast: SchemaAST.ASTast: import SchemaASTSchemaAST.type AST = SchemaAST.Declaration | SchemaAST.Null | SchemaAST.Undefined | SchemaAST.Void | SchemaAST.Never | SchemaAST.Unknown | SchemaAST.Any | SchemaAST.String | SchemaAST.Number | SchemaAST.Boolean | SchemaAST.BigInt | SchemaAST.Symbol | SchemaAST.Literal | SchemaAST.UniqueSymbol | SchemaAST.ObjectKeyword | SchemaAST.Enum | SchemaAST.TemplateLiteral | SchemaAST.Arrays | SchemaAST.Objects | SchemaAST.Union<...> | SchemaAST.SuspendDiscriminated union of all AST node types.
Details
Every Schema has an .ast property of this type. Use the guard functions
(
isString
,
isObjects
, etc.) to narrow to a specific variant,
then access variant-specific fields.
- All variants share the
Base
fields:
annotations, checks,
encoding, context.
- Discriminate on the
_tag field (e.g. "String", "Objects", "Union").
AST) => import FormatterFormatter<any>) => import FormatterFormatter<any> | undefined)
| undefined
}): import FormatterFormatter<function (type parameter) S in toFormatter<S extends Constraint>(schema: S, options?: {
readonly onBefore?: ((ast: SchemaAST.AST, recur: (ast: SchemaAST.AST) => Formatter<any>) => Formatter<any> | undefined) | undefined;
}): Formatter<S["Type"]>
S["Type"]> {
return function (local function) recur(ast: SchemaAST.AST): Formatter<S['Type']>recur(schema: S extends Constraintschema.Constraint["ast"]: SchemaAST.ASTast)
function function (local function) recur(ast: SchemaAST.AST): Formatter<S['Type']>recur(ast: SchemaAST.ASTast: import SchemaASTSchemaAST.type AST = SchemaAST.Declaration | SchemaAST.Null | SchemaAST.Undefined | SchemaAST.Void | SchemaAST.Never | SchemaAST.Unknown | SchemaAST.Any | SchemaAST.String | SchemaAST.Number | SchemaAST.Boolean | SchemaAST.BigInt | SchemaAST.Symbol | SchemaAST.Literal | SchemaAST.UniqueSymbol | SchemaAST.ObjectKeyword | SchemaAST.Enum | SchemaAST.TemplateLiteral | SchemaAST.Arrays | SchemaAST.Objects | SchemaAST.Union<...> | SchemaAST.SuspendDiscriminated union of all AST node types.
Details
Every Schema has an .ast property of this type. Use the guard functions
(
isString
,
isObjects
, etc.) to narrow to a specific variant,
then access variant-specific fields.
- All variants share the
Base
fields:
annotations, checks,
encoding, context.
- Discriminate on the
_tag field (e.g. "String", "Objects", "Union").
AST): import FormatterFormatter<function (type parameter) S in toFormatter<S extends Constraint>(schema: S, options?: {
readonly onBefore?: ((ast: SchemaAST.AST, recur: (ast: SchemaAST.AST) => Formatter<any>) => Formatter<any> | undefined) | undefined;
}): Formatter<S["Type"]>
S["Type"]> {
// ---------------------------------------------
// handle annotation
// ---------------------------------------------
const const annotation: unknownannotation = import InternalAnnotationsInternalAnnotations.function resolve(
ast: SchemaAST.AST
): Annotations.Annotations | undefined
resolve(ast: SchemaAST.ASTast)?.["toFormatter"]
if (typeof const annotation: unknownannotation === "function") {
return const annotation: Functionannotation(import SchemaASTSchemaAST.const isDeclaration: (
ast: AST
) => ast is Declaration
Narrows an
AST
to
Declaration
.
When to use
Use to recognize declaration AST nodes before running declaration-specific
handling.
isDeclaration(ast: SchemaAST.ASTast) ? ast: SchemaAST.AST(parameter) ast: {
_tag: 'Declaration';
typeParameters: ReadonlyArray<AST>;
run: (typeParameters: ReadonlyArray<AST>) => (input: unknown, self: Declaration, options: ParseOptions) => Effect.Effect<any, SchemaIssue.Issue, any>;
encodingChecks: Checks | undefined;
getParser: () => SchemaParser.Parser;
_rebuild: (recur: (ast: AST) => AST, checks: Checks | undefined, encodingChecks: Checks | undefined) => Declaration;
recur: (recur: (ast: AST) => AST) => Declaration;
flip: (recur: (ast: AST) => AST) => Declaration;
getExpected: () => string;
annotations: Schema.Annotations.Annotations | undefined;
checks: Checks | undefined;
encoding: Encoding | undefined;
context: Context | undefined;
toString: () => string;
}
ast.Declaration.typeParameters: ReadonlyArray<AST>typeParameters.ReadonlyArray<AST>.map<Formatter<S["Type"]>>(callbackfn: (value: SchemaAST.AST, index: number, array: readonly SchemaAST.AST[]) => Formatter<S["Type"]>, thisArg?: any): Formatter<S["Type"]>[]Calls a defined callback function on each element of an array, and returns an array that contains the results.
map(function (local function) recur(ast: SchemaAST.AST): Formatter<S['Type']>recur) : [])
}
// ---------------------------------------------
// handle onBefore
// ---------------------------------------------
if (options: {
readonly onBefore?:
| ((
ast: SchemaAST.AST,
recur: (
ast: SchemaAST.AST
) => Formatter<any>
) => Formatter<any> | undefined)
| undefined
}
options?.onBefore?: | ((
ast: SchemaAST.AST,
recur: (
ast: SchemaAST.AST
) => Formatter<any>
) => Formatter<any> | undefined)
| undefined
onBefore) {
const const onBefore: anyonBefore = options: {
readonly onBefore?:
| ((
ast: SchemaAST.AST,
recur: (
ast: SchemaAST.AST
) => Formatter<any>
) => Formatter<any> | undefined)
| undefined
}
options.onBefore?: | ((
ast: SchemaAST.AST,
recur: (
ast: SchemaAST.AST
) => Formatter<any>
) => Formatter<any> | undefined)
| undefined
onBefore(ast: SchemaAST.ASTast, function (local function) recur(ast: SchemaAST.AST): Formatter<S['Type']>recur)
if (const onBefore: anyonBefore !== var undefinedundefined) {
return const onBefore: Formatter<any, string>onBefore
}
}
// ---------------------------------------------
// handle base case
// ---------------------------------------------
return function (local function) on(ast: SchemaAST.AST): Formatter<any>on(ast: SchemaAST.ASTast)
}
function function (local function) on(ast: SchemaAST.AST): Formatter<any>on(ast: SchemaAST.ASTast: import SchemaASTSchemaAST.type AST = SchemaAST.Declaration | SchemaAST.Null | SchemaAST.Undefined | SchemaAST.Void | SchemaAST.Never | SchemaAST.Unknown | SchemaAST.Any | SchemaAST.String | SchemaAST.Number | SchemaAST.Boolean | SchemaAST.BigInt | SchemaAST.Symbol | SchemaAST.Literal | SchemaAST.UniqueSymbol | SchemaAST.ObjectKeyword | SchemaAST.Enum | SchemaAST.TemplateLiteral | SchemaAST.Arrays | SchemaAST.Objects | SchemaAST.Union<...> | SchemaAST.SuspendDiscriminated union of all AST node types.
Details
Every Schema has an .ast property of this type. Use the guard functions
(
isString
,
isObjects
, etc.) to narrow to a specific variant,
then access variant-specific fields.
- All variants share the
Base
fields:
annotations, checks,
encoding, context.
- Discriminate on the
_tag field (e.g. "String", "Objects", "Union").
AST): import FormatterFormatter<any> {
switch (ast: SchemaAST.ASTast._tag: | "Declaration"
| "Null"
| "Undefined"
| "Void"
| "Never"
| "Unknown"
| "Any"
| "String"
| "Number"
| "Boolean"
| "BigInt"
| "Symbol"
| "Literal"
| "UniqueSymbol"
| "ObjectKeyword"
| "Enum"
| "TemplateLiteral"
| "Arrays"
| "Objects"
| "Union"
| "Suspend"
_tag) {
default:
return import formatformat
case "Never":
return () => "never"
case "Void":
return () => "void"
case "Arrays": {
const const elements: Array<
Formatter<S["Type"], string>
>
elements = ast: SchemaAST.AST(parameter) ast: {
_tag: 'Arrays';
isMutable: boolean;
elements: ReadonlyArray<AST>;
rest: ReadonlyArray<AST>;
encodingChecks: Checks | undefined;
getParser: (recur: (ast: AST) => SchemaParser.Parser) => SchemaParser.Parser;
_rebuild: (recur: (ast: AST) => AST, checks: Checks | undefined, encodingChecks: Checks | undefined) => Arrays;
recur: (recur: (ast: AST) => AST) => Arrays;
flip: (recur: (ast: AST) => AST) => Arrays;
getExpected: () => string;
annotations: Schema.Annotations.Annotations | undefined;
checks: Checks | undefined;
encoding: Encoding | undefined;
context: Context | undefined;
toString: () => string;
}
ast.Arrays.elements: ReadonlyArray<AST>elements.ReadonlyArray<AST>.map<Formatter<S["Type"]>>(callbackfn: (value: SchemaAST.AST, index: number, array: readonly SchemaAST.AST[]) => Formatter<S["Type"]>, thisArg?: any): Formatter<S["Type"]>[]Calls a defined callback function on each element of an array, and returns an array that contains the results.
map(function (local function) recur(ast: SchemaAST.AST): Formatter<S['Type']>recur)
const const rest: Array<
Formatter<S["Type"], string>
>
rest = ast: SchemaAST.AST(parameter) ast: {
_tag: 'Arrays';
isMutable: boolean;
elements: ReadonlyArray<AST>;
rest: ReadonlyArray<AST>;
encodingChecks: Checks | undefined;
getParser: (recur: (ast: AST) => SchemaParser.Parser) => SchemaParser.Parser;
_rebuild: (recur: (ast: AST) => AST, checks: Checks | undefined, encodingChecks: Checks | undefined) => Arrays;
recur: (recur: (ast: AST) => AST) => Arrays;
flip: (recur: (ast: AST) => AST) => Arrays;
getExpected: () => string;
annotations: Schema.Annotations.Annotations | undefined;
checks: Checks | undefined;
encoding: Encoding | undefined;
context: Context | undefined;
toString: () => string;
}
ast.Arrays.rest: ReadonlyArray<AST>rest.ReadonlyArray<AST>.map<Formatter<S["Type"]>>(callbackfn: (value: SchemaAST.AST, index: number, array: readonly SchemaAST.AST[]) => Formatter<S["Type"]>, thisArg?: any): Formatter<S["Type"]>[]Calls a defined callback function on each element of an array, and returns an array that contains the results.
map(function (local function) recur(ast: SchemaAST.AST): Formatter<S['Type']>recur)
return (t: anyt) => {
const const out: string[]out: interface Array<T>Array<string> = []
let let i: numberi = 0
// ---------------------------------------------
// handle elements
// ---------------------------------------------
for (; let i: numberi < const elements: Array<
Formatter<S["Type"], string>
>
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; let i: numberi++) {
if (t: anyt.length < let i: numberi + 1) {
if (import SchemaASTSchemaAST.function isOptional(ast: AST): booleanReturns true if the AST node represents an optional property.
Details
Checks ast.context?.isOptional. Defaults to false when no
Context
is set.
isOptional(ast: SchemaAST.AST(parameter) ast: {
_tag: 'Arrays';
isMutable: boolean;
elements: ReadonlyArray<AST>;
rest: ReadonlyArray<AST>;
encodingChecks: Checks | undefined;
getParser: (recur: (ast: AST) => SchemaParser.Parser) => SchemaParser.Parser;
_rebuild: (recur: (ast: AST) => AST, checks: Checks | undefined, encodingChecks: Checks | undefined) => Arrays;
recur: (recur: (ast: AST) => AST) => Arrays;
flip: (recur: (ast: AST) => AST) => Arrays;
getExpected: () => string;
annotations: Schema.Annotations.Annotations | undefined;
checks: Checks | undefined;
encoding: Encoding | undefined;
context: Context | undefined;
toString: () => string;
}
ast.Arrays.elements: ReadonlyArray<AST>elements[let i: numberi])) {
continue
}
} else {
const out: string[]out.Array<string>.push(...items: string[]): numberAppends new elements to the end of an array, and returns the new length of the array.
push(const elements: Array<
Formatter<S["Type"], string>
>
elements[let i: numberi](t: anyt[let i: numberi]))
}
}
// ---------------------------------------------
// handle rest element
// ---------------------------------------------
if (const rest: Array<
Formatter<S["Type"], string>
>
rest.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 [const head: Formatter<S["Type"], string>head, ...const tail: Array<
Formatter<S["Type"], string>
>
tail] = const rest: Array<
Formatter<S["Type"], string>
>
rest
for (; let i: numberi < t: anyt.length - const tail: Array<
Formatter<S["Type"], string>
>
tail.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; let i: numberi++) {
const out: string[]out.Array<string>.push(...items: string[]): numberAppends new elements to the end of an array, and returns the new length of the array.
push(const head: Formatter<S["Type"], string>head(t: anyt[let i: numberi]))
}
// ---------------------------------------------
// handle post rest elements
// ---------------------------------------------
for (let let j: numberj = 0; let j: numberj < const tail: Array<
Formatter<S["Type"], string>
>
tail.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; let j: numberj++) {
const out: string[]out.Array<string>.push(...items: string[]): numberAppends new elements to the end of an array, and returns the new length of the array.
push(const tail: Array<
Formatter<S["Type"], string>
>
tail[let j: numberj](t: anyt[let i: numberi + let j: numberj]))
}
}
return "[" + const out: string[]out.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 propertySignatures: Array<
Formatter<S["Type"], string>
>
propertySignatures = ast: SchemaAST.AST(parameter) ast: {
_tag: 'Objects';
propertySignatures: ReadonlyArray<PropertySignature>;
indexSignatures: ReadonlyArray<IndexSignature>;
encodingChecks: Checks | undefined;
getParser: (recur: (ast: AST) => SchemaParser.Parser) => SchemaParser.Parser;
_rebuild: (recur: (ast: AST) => AST, recurParameter: (ast: AST) => AST, flipMerge: boolean, checks: Checks | undefined, encodingChecks: Checks | undefined) => Objects;
flip: (recur: (ast: AST) => AST) => AST;
recur: (recur: (ast: AST) => AST, recurParameter?: (ast: AST) => AST) => AST;
getExpected: () => string;
annotations: Schema.Annotations.Annotations | undefined;
checks: Checks | undefined;
encoding: Encoding | undefined;
context: Context | undefined;
toString: () => string;
}
ast.Objects.propertySignatures: ReadonlyArray<PropertySignature>propertySignatures.ReadonlyArray<PropertySignature>.map<Formatter<S["Type"]>>(callbackfn: (value: SchemaAST.PropertySignature, index: number, array: readonly SchemaAST.PropertySignature[]) => Formatter<S["Type"]>, thisArg?: any): Formatter<S["Type"]>[]Calls a defined callback function on each element of an array, and returns an array that contains the results.
map((ps: SchemaAST.PropertySignature(parameter) ps: {
name: PropertyKey;
type: AST;
}
ps) => function (local function) recur(ast: SchemaAST.AST): Formatter<S['Type']>recur(ps: SchemaAST.PropertySignature(parameter) ps: {
name: PropertyKey;
type: AST;
}
ps.PropertySignature.type: ASTtype))
const const indexSignatures: Array<
Formatter<S["Type"], string>
>
indexSignatures = ast: SchemaAST.AST(parameter) ast: {
_tag: 'Objects';
propertySignatures: ReadonlyArray<PropertySignature>;
indexSignatures: ReadonlyArray<IndexSignature>;
encodingChecks: Checks | undefined;
getParser: (recur: (ast: AST) => SchemaParser.Parser) => SchemaParser.Parser;
_rebuild: (recur: (ast: AST) => AST, recurParameter: (ast: AST) => AST, flipMerge: boolean, checks: Checks | undefined, encodingChecks: Checks | undefined) => Objects;
flip: (recur: (ast: AST) => AST) => AST;
recur: (recur: (ast: AST) => AST, recurParameter?: (ast: AST) => AST) => AST;
getExpected: () => string;
annotations: Schema.Annotations.Annotations | undefined;
checks: Checks | undefined;
encoding: Encoding | undefined;
context: Context | undefined;
toString: () => string;
}
ast.Objects.indexSignatures: ReadonlyArray<IndexSignature>indexSignatures.ReadonlyArray<IndexSignature>.map<Formatter<S["Type"]>>(callbackfn: (value: SchemaAST.IndexSignature, index: number, array: readonly SchemaAST.IndexSignature[]) => Formatter<S["Type"]>, thisArg?: any): Formatter<S["Type"]>[]Calls a defined callback function on each element of an array, and returns an array that contains the results.
map((is: SchemaAST.IndexSignature(parameter) is: {
parameter: IndexSignatureParameter;
type: AST;
merge: KeyValueCombiner | undefined;
}
is) => function (local function) recur(ast: SchemaAST.AST): Formatter<S['Type']>recur(is: SchemaAST.IndexSignature(parameter) is: {
parameter: IndexSignatureParameter;
type: AST;
merge: KeyValueCombiner | undefined;
}
is.IndexSignature.type: ASTtype))
if (ast: SchemaAST.AST(parameter) ast: {
_tag: 'Objects';
propertySignatures: ReadonlyArray<PropertySignature>;
indexSignatures: ReadonlyArray<IndexSignature>;
encodingChecks: Checks | undefined;
getParser: (recur: (ast: AST) => SchemaParser.Parser) => SchemaParser.Parser;
_rebuild: (recur: (ast: AST) => AST, recurParameter: (ast: AST) => AST, flipMerge: boolean, checks: Checks | undefined, encodingChecks: Checks | undefined) => Objects;
flip: (recur: (ast: AST) => AST) => AST;
recur: (recur: (ast: AST) => AST, recurParameter?: (ast: AST) => AST) => AST;
getExpected: () => string;
annotations: Schema.Annotations.Annotations | undefined;
checks: Checks | undefined;
encoding: Encoding | undefined;
context: Context | undefined;
toString: () => string;
}
ast.Objects.propertySignatures: ReadonlyArray<PropertySignature>propertySignatures.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 && ast: SchemaAST.AST(parameter) ast: {
_tag: 'Objects';
propertySignatures: ReadonlyArray<PropertySignature>;
indexSignatures: ReadonlyArray<IndexSignature>;
encodingChecks: Checks | undefined;
getParser: (recur: (ast: AST) => SchemaParser.Parser) => SchemaParser.Parser;
_rebuild: (recur: (ast: AST) => AST, recurParameter: (ast: AST) => AST, flipMerge: boolean, checks: Checks | undefined, encodingChecks: Checks | undefined) => Objects;
flip: (recur: (ast: AST) => AST) => AST;
recur: (recur: (ast: AST) => AST, recurParameter?: (ast: AST) => AST) => AST;
getExpected: () => string;
annotations: Schema.Annotations.Annotations | undefined;
checks: Checks | undefined;
encoding: Encoding | undefined;
context: Context | undefined;
toString: () => string;
}
ast.Objects.indexSignatures: ReadonlyArray<IndexSignature>indexSignatures.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 import formatformat
}
return (t: anyt) => {
const const out: string[]out: interface Array<T>Array<string> = []
const const visited: Set<PropertyKey>visited = new var Set: SetConstructor
new <PropertyKey>(iterable?: Iterable<PropertyKey> | null | undefined) => Set<PropertyKey> (+1 overload)
Set<type PropertyKey =
| string
| number
| symbol
PropertyKey>()
// ---------------------------------------------
// handle property signatures
// ---------------------------------------------
for (let let i: numberi = 0; let i: numberi < const propertySignatures: Array<
Formatter<S["Type"], string>
>
propertySignatures.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; let i: numberi++) {
const const ps: SchemaAST.PropertySignatureconst ps: {
name: PropertyKey;
type: AST;
}
ps = ast: SchemaAST.AST(parameter) ast: {
_tag: 'Objects';
propertySignatures: ReadonlyArray<PropertySignature>;
indexSignatures: ReadonlyArray<IndexSignature>;
encodingChecks: Checks | undefined;
getParser: (recur: (ast: AST) => SchemaParser.Parser) => SchemaParser.Parser;
_rebuild: (recur: (ast: AST) => AST, recurParameter: (ast: AST) => AST, flipMerge: boolean, checks: Checks | undefined, encodingChecks: Checks | undefined) => Objects;
flip: (recur: (ast: AST) => AST) => AST;
recur: (recur: (ast: AST) => AST, recurParameter?: (ast: AST) => AST) => AST;
getExpected: () => string;
annotations: Schema.Annotations.Annotations | undefined;
checks: Checks | undefined;
encoding: Encoding | undefined;
context: Context | undefined;
toString: () => string;
}
ast.Objects.propertySignatures: ReadonlyArray<PropertySignature>propertySignatures[let i: numberi]
const const name: PropertyKeyname = const ps: SchemaAST.PropertySignatureconst ps: {
name: PropertyKey;
type: AST;
}
ps.PropertySignature.name: PropertyKeyname
const visited: Set<PropertyKey>visited.Set<PropertyKey>.add(value: PropertyKey): Set<PropertyKey>Appends a new element with a specified value to the end of the Set.
add(const name: PropertyKeyname)
if (import SchemaASTSchemaAST.function isOptional(ast: AST): booleanReturns true if the AST node represents an optional property.
Details
Checks ast.context?.isOptional. Defaults to false when no
Context
is set.
isOptional(const ps: SchemaAST.PropertySignatureconst ps: {
name: PropertyKey;
type: AST;
}
ps.PropertySignature.type: ASTtype) && !var Object: ObjectConstructorProvides functionality common to all JavaScript objects.
Object.ObjectConstructor.hasOwn(o: object, v: PropertyKey): booleanDetermines whether an object has a property with the specified name.
hasOwn(t: anyt, const name: PropertyKeyname)) {
continue
}
const out: string[]out.Array<string>.push(...items: string[]): numberAppends new elements to the end of an array, and returns the new length of the array.
push(`${import formatPropertyKeyformatPropertyKey(const name: PropertyKeyname)}: ${const propertySignatures: Array<
Formatter<S["Type"], string>
>
propertySignatures[let i: numberi](t: anyt[const name: PropertyKeyname])}`)
}
// ---------------------------------------------
// handle index signatures
// ---------------------------------------------
for (let let i: numberi = 0; let i: numberi < const indexSignatures: Array<
Formatter<S["Type"], string>
>
indexSignatures.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; let i: numberi++) {
const const keys: readonly PropertyKey[]keys = import SchemaASTSchemaAST.function getIndexSignatureKeys(
input: { readonly [x: PropertyKey]: unknown },
parameter: IndexSignatureParameter,
options?: ParseOptions
): ReadonlyArray<PropertyKey>
Returns the object keys that match the index signature parameter schema.
getIndexSignatureKeys(t: anyt, ast: SchemaAST.AST(parameter) ast: {
_tag: 'Objects';
propertySignatures: ReadonlyArray<PropertySignature>;
indexSignatures: ReadonlyArray<IndexSignature>;
encodingChecks: Checks | undefined;
getParser: (recur: (ast: AST) => SchemaParser.Parser) => SchemaParser.Parser;
_rebuild: (recur: (ast: AST) => AST, recurParameter: (ast: AST) => AST, flipMerge: boolean, checks: Checks | undefined, encodingChecks: Checks | undefined) => Objects;
flip: (recur: (ast: AST) => AST) => AST;
recur: (recur: (ast: AST) => AST, recurParameter?: (ast: AST) => AST) => AST;
getExpected: () => string;
annotations: Schema.Annotations.Annotations | undefined;
checks: Checks | undefined;
encoding: Encoding | undefined;
context: Context | undefined;
toString: () => string;
}
ast.Objects.indexSignatures: ReadonlyArray<IndexSignature>indexSignatures[let i: numberi].IndexSignature.parameter: IndexSignatureParameterparameter)
for (const const key: PropertyKeykey of const keys: readonly PropertyKey[]keys) {
if (const visited: Set<PropertyKey>visited.Set<PropertyKey>.has(value: PropertyKey): booleanhas(const key: PropertyKeykey)) {
continue
}
const visited: Set<PropertyKey>visited.Set<PropertyKey>.add(value: PropertyKey): Set<PropertyKey>Appends a new element with a specified value to the end of the Set.
add(const key: PropertyKeykey)
const out: string[]out.Array<string>.push(...items: string[]): numberAppends new elements to the end of an array, and returns the new length of the array.
push(`${import formatPropertyKeyformatPropertyKey(const key: PropertyKeykey)}: ${const indexSignatures: Array<
Formatter<S["Type"], string>
>
indexSignatures[let i: numberi](t: anyt[const key: PropertyKeykey])}`)
}
}
return const out: string[]out.Array<string>.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 out: string[]out.Array<string>.join(separator?: string): stringAdds all the elements of an array into a string, separated by the specified separator string.
join(", ") + " }" : "{}"
}
}
case "Union": {
const const getCandidates: (
t: any
) => readonly SchemaAST.AST[]
getCandidates = (t: anyt: any) => import SchemaASTSchemaAST.function getCandidates(
input: any,
types: ReadonlyArray<AST>
): ReadonlyArray<AST>
The goal is to reduce the number of a union members that will be checked.
This is useful to reduce the number of issues that will be returned.
getCandidates(t: anyt, ast: SchemaAST.AST(parameter) ast: {
_tag: 'Union';
types: ReadonlyArray<A>;
mode: "anyOf" | "oneOf";
encodingChecks: Checks | undefined;
getParser: (recur: (ast: AST) => SchemaParser.Parser) => SchemaParser.Parser;
_rebuild: (recur: (ast: AST) => AST, checks: Checks | undefined, encodingChecks: Checks | undefined) => Union<AST>;
recur: (recur: (ast: AST) => AST) => Union<AST>;
flip: (recur: (ast: AST) => AST) => Union<AST>;
matchPart: (s: string, options: ParseOptions) => LiteralValue | undefined;
getExpected: (getExpected: (ast: AST) => string) => string;
annotations: Schema.Annotations.Annotations | undefined;
checks: Checks | undefined;
encoding: Encoding | undefined;
context: Context | undefined;
toString: () => string;
}
ast.Union<AST>.types: readonly SchemaAST.AST[]types)
return (t: anyt) => {
const const candidates: ReadonlyArray<SchemaAST.AST>candidates = const getCandidates: (
t: any
) => readonly SchemaAST.AST[]
getCandidates(t: anyt)
const const refinements: (<I>(
input: I
) => input is I)[]
refinements = const candidates: ReadonlyArray<SchemaAST.AST>candidates.ReadonlyArray<AST>.map<<I>(input: I) => input is I>(callbackfn: (value: SchemaAST.AST, index: number, array: readonly SchemaAST.AST[]) => <I>(input: I) => input is I, thisArg?: any): (<I>(input: I) => input is I)[]Calls a defined callback function on each element of an array, and returns an array that contains the results.
map(import SchemaParserSchemaParser.function _is<T>(
ast: SchemaAST.AST
): <I>(input: I) => input is I & T
_is)
for (let let i: numberi = 0; let i: numberi < const candidates: ReadonlyArray<SchemaAST.AST>candidates.ReadonlyArray<AST>.length: numberGets the length of the array. This is a number one higher than the highest element defined in an array.
length; let i: numberi++) {
const const is: <I>(input: I) => input is Iis = const refinements: (<I>(
input: I
) => input is I)[]
refinements[let i: numberi]
if (const is: <any>(
input: any
) => input is I & T
is(t: anyt)) {
return function (local function) recur(ast: SchemaAST.AST): Formatter<S['Type']>recur(const candidates: ReadonlyArray<SchemaAST.AST>candidates[let i: numberi])(t: anyt)
}
}
return import formatformat(t: anyt)
}
}
case "Suspend": {
const const get: () => Formatter<S["Type"]>get = import SchemaASTSchemaAST.function memoizeThunk<Formatter<S["Type"]>>(f: () => Formatter<S["Type"]>): () => Formatter<S["Type"]>memoizeThunk(() => function (local function) recur(ast: SchemaAST.AST): Formatter<S['Type']>recur(ast: SchemaAST.AST(parameter) ast: {
_tag: 'Suspend';
thunk: () => AST;
getParser: (recur: (ast: AST) => SchemaParser.Parser) => SchemaParser.Parser;
recur: (recur: (ast: AST) => AST) => Suspend;
getExpected: (getExpected: (ast: AST) => string) => string;
annotations: Schema.Annotations.Annotations | undefined;
checks: Checks | undefined;
encoding: Encoding | undefined;
context: Context | undefined;
toString: () => string;
}
ast.Suspend.thunk: () => ASTthunk()))
return (t: anyt) => const get: () => Formatter<S["Type"]>get()(t: anyt)
}
}
}
}