Package: effect
Module: SchemaAST
AST node for object-like schemas, including structs and records.
When to use
Use when constructing or inspecting AST nodes for structs or records rather than array-like schemas.
Details
propertySignatures — named properties with their types (struct fields).indexSignatures — index signature entries (record patterns), each with
a parameter AST for matching keys and a type AST for values.An Objects node with no properties and no index signatures performs only a
non-nullish check: it accepts any value except null and undefined,
including primitive values.
Gotchas
Duplicate property names throw at construction time.
Example (Inspecting a struct AST)
import { Schema, SchemaAST } from "effect"
const schema = Schema.Struct({ name: Schema.String })
const ast = schema.ast
if (SchemaAST.isObjects(ast)) {
for (const ps of ast.propertySignatures) {
console.log(ps.name, ps.type._tag)
}
// "name" "String"
}
See
isObjectsPropertySignatureIndexSignatureArraysSignature
declare class Objects { constructor(
propertySignatures: ReadonlyArray<PropertySignature>,
indexSignatures: ReadonlyArray<IndexSignature>,
annotations?: Schema.Annotations.Annotations,
checks?: Checks,
encoding?: Encoding,
context?: Context,
encodingChecks?: Checks
) }
Since v4.0.0