IndexSignatureRepresents an index signature entry within an Objects node.
When to use
Use when constructing or inspecting object AST entries for record-like keys and values.
Details
parameter— the key type AST (e.g. String forstringkeys, TemplateLiteral for patterned keys).type— the value type SchemaAST.merge— optional KeyValueCombiner for handling duplicate keys.
Gotchas
Using Schema.optionalKey on the value type is not allowed for index
signatures (throws at construction); use Schema.optional instead.
export class class IndexSignatureclass IndexSignature {
parameter: IndexSignatureParameter;
type: AST;
merge: KeyValueCombiner | undefined;
}
Represents an index signature entry within an
Objects
node.
When to use
Use when constructing or inspecting object AST entries for record-like keys
and values.
Details
parameter — the key type AST (e.g.
String
for string keys,
TemplateLiteral
for patterned keys).
type — the value type SchemaAST.
merge — optional
KeyValueCombiner
for handling duplicate keys.
Gotchas
Using Schema.optionalKey on the value type is not allowed for index
signatures (throws at construction); use Schema.optional instead.
IndexSignature {
readonly IndexSignature.parameter: IndexSignatureParameterparameter: type IndexSignatureParameter =
| String
| Number
| Symbol
| TemplateLiteral
| Union<IndexSignatureParameter>
IndexSignatureParameter
readonly IndexSignature.type: ASTtype: type AST =
| Declaration
| Null
| Undefined
| Void
| Never
| Unknown
| Any
| String
| Number
| Boolean
| BigInt
| Symbol
| Literal
| UniqueSymbol
| ObjectKeyword
| Enum
| TemplateLiteral
| Arrays
| Objects
| Union<AST>
| Suspend
Discriminated 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
readonly IndexSignature.merge: KeyValueCombiner | undefinedmerge: class KeyValueCombinerclass KeyValueCombiner {
decode: Combiner.Combiner<readonly [key: PropertyKey, value: any]> | undefined;
encode: Combiner.Combiner<readonly [key: PropertyKey, value: any]> | undefined;
flip: () => KeyValueCombiner;
}
Represents a bidirectional merge strategy for index signature key-value pairs.
Details
Used by
IndexSignature
when the same key appears multiple times
(e.g. from Schema.extend or overlapping records). Provides separate
decode and encode combiners that determine how duplicate entries are
merged.
KeyValueCombiner | undefined
constructor(
parameter: ASTparameter: type AST =
| Declaration
| Null
| Undefined
| Void
| Never
| Unknown
| Any
| String
| Number
| Boolean
| BigInt
| Symbol
| Literal
| UniqueSymbol
| ObjectKeyword
| Enum
| TemplateLiteral
| Arrays
| Objects
| Union<AST>
| Suspend
Discriminated 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,
type: ASTtype: type AST =
| Declaration
| Null
| Undefined
| Void
| Never
| Unknown
| Any
| String
| Number
| Boolean
| BigInt
| Symbol
| Literal
| UniqueSymbol
| ObjectKeyword
| Enum
| TemplateLiteral
| Arrays
| Objects
| Union<AST>
| Suspend
Discriminated 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,
merge: KeyValueCombiner | undefinedmerge: class KeyValueCombinerclass KeyValueCombiner {
decode: Combiner.Combiner<readonly [key: PropertyKey, value: any]> | undefined;
encode: Combiner.Combiner<readonly [key: PropertyKey, value: any]> | undefined;
flip: () => KeyValueCombiner;
}
Represents a bidirectional merge strategy for index signature key-value pairs.
Details
Used by
IndexSignature
when the same key appears multiple times
(e.g. from Schema.extend or overlapping records). Provides separate
decode and encode combiners that determine how duplicate entries are
merged.
KeyValueCombiner | undefined
) {
if (!function isIndexSignatureParameter(
ast: AST
): ast is IndexSignatureParameter
isIndexSignatureParameter(parameter: ASTparameter)) {
throw new var Error: ErrorConstructor
new (message?: string, options?: ErrorOptions) => Error (+1 overload)
Error(`Invalid index signature parameter ${parameter: ASTparameter._tag: | "Declaration"
| "Null"
| "Undefined"
| "Void"
| "Never"
| "Unknown"
| "Any"
| "Boolean"
| "BigInt"
| "Literal"
| "UniqueSymbol"
| "ObjectKeyword"
| "Enum"
| "Arrays"
| "Objects"
| "Union"
| "Suspend"
_tag}`)
}
this.IndexSignature.parameter: IndexSignatureParameterparameter = parameter: ASTparameter
this.IndexSignature.type: ASTtype = type: ASTtype
this.IndexSignature.merge: KeyValueCombiner | undefinedmerge = merge: KeyValueCombiner | undefinedmerge
if (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(type: ASTtype) && !function containsUndefined(
ast: AST
): boolean
containsUndefined(type: ASTtype)) {
throw new var Error: ErrorConstructor
new (message?: string, options?: ErrorOptions) => Error (+1 overload)
Error("Cannot use `Schema.optionalKey` with index signatures, use `Schema.optional` instead.")
}
}
}