ConstraintLightweight structural constraint for APIs that accept schema values but only read their data and type-level views.
When to use
Use when you need to constrain a generic value to be a schema, but the API
only reads properties such as ast, Type, Encoded, service
requirements, constructor input views, or modifier flags.
Details
Constraint keeps the schema type identifier and the property surface needed
by schema constructors, while avoiding the full Bottom protocol. Use
Top when an API calls schema methods such as annotate, check,
rebuild, make, or makeEffect.
export interface Constraint {
readonly [const TypeId: "~effect/Schema/Schema"TypeId]: typeof const TypeId: "~effect/Schema/Schema"TypeId
readonly "ast": 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
readonly "Type": unknown
readonly "Encoded": unknown
readonly "DecodingServices": unknown
readonly "EncodingServices": unknown
readonly "~type.parameters": any
readonly "~type.make.in": unknown
readonly "~type.make": unknown
readonly "Iso": unknown
readonly "~type.optionality": type Optionality = "required" | "optional"Whether a schema field is required or optional within a struct.
Optionality
readonly "~type.mutability": type Mutability = "readonly" | "mutable"Whether a schema field is readonly or mutable within a struct.
Mutability
readonly "~type.constructor.default": type ConstructorDefault =
| "no-default"
| "with-default"
Whether a schema field has a constructor default value.
ConstructorDefault
readonly "~encoded.optionality": type Optionality = "required" | "optional"Whether a schema field is required or optional within a struct.
Optionality
readonly "~encoded.mutability": type Mutability = "readonly" | "mutable"Whether a schema field is readonly or mutable within a struct.
Mutability
}