Advanced Patterns
todo - Cover advanced schema techniques and edge cases. Include:
Wildcards
- Using
'*'as a property name for fallback/default behavior - Wildcards in object schemas (unknown properties)
- Wildcards in array schemas (member schemas)
- Resolution precedence: named properties > wildcard
Tuples
- Explicit array indices as property names:
'0','1','2' - Combining explicit indices with wildcard for overflow
- Use cases for heterogeneous arrays
Value Constraints
Schema.literal(value)for exact matchesvaluesoption for enumsmin/maxfor numeric ranges- How value constraints accumulate through inheritance
Container Transformers
- Transformers on object/array schemas generate initial containers
- They do NOT transform the final assembled result
- Receive initial value (often
truefor resolution success) - Must return object/array that can have properties set incrementally
- Use
.lax()if transformer adds properties not in schema
Complex Conditions
- Conditional suppression patterns
- Conditions that depend on multiple config values
- Returning
undefinedfor deferred evaluation - Using conditions to implement feature flags
Meta and Custom Options
- Using
.meta(key, value)for documentation/tooling - Custom options for domain-specific behavior
- How options are inherited and merged
Union Staging Area
- How discriminator functions receive values
- Values accumulate in staging area until union resolves
- Union members cannot see staging area values
Schema Composition Patterns
- Reusing schema definitions
- Building schema libraries
- Modular schema organization across files
Key point: These patterns enable sophisticated configuration structures while maintaining type safety and validation.