Overview
Schema is a core Effect module that enables:- Type-safe validation with automatic TypeScript inference
- Data transformation between different representations
- Serialization and deserialization
- Error handling with detailed validation errors
- Schema composition for complex data structures
Basic Schemas
Primitive Types
Define schemas for basic types:Struct Schemas
Define object structures:Array and Union Schemas
Validation
Decoding and Encoding
Schemas support bidirectional transformation:Validation with Refinements
Add custom validation rules:Handling Validation Errors
Transformations
Schema Transformations
Transform data between different representations:Complex Transformations
Tagged Schemas
Tagged Unions
Create discriminated unions with tags:Pattern Matching with Tags
Schema Classes
TaggedErrorClass
Create error classes with schemas:Error Handling with Tagged Errors
Class-Based Schemas
Schema Classes
Create class instances with validation:TaggedClass
Classes with discriminator tags:Advanced Features
Optional and Default Values
Brand Types
Create nominal types with brands:Recursive Schemas
Define self-referential schemas:JSON Schema Generation
Generate JSON Schema from Effect schemas:Best Practices
Define schemas close to usage
Define schemas close to usage
Keep schema definitions near the code that uses them:
Use TaggedErrorClass for errors
Use TaggedErrorClass for errors
Create typed error classes with schema validation:
Compose schemas
Compose schemas
Build complex schemas from simpler ones:
Leverage transformations
Leverage transformations
Use decodeTo for representing data differently:
Related
SQL
Build type-safe SQL queries
Caching
Cache validated data efficiently
