Skip to content

compose

compose<T>(base, …extension): Schema<T>

Defined in: projects/ngx-signal-schema/src/lib/composition/compose.ts:32

Combines multiple schemas into a single schema.

The compose function allows extending a base schema with additional schemas or conditions. This is particularly useful for reusing existing validation logic and augmenting it with context-specific conditions (e.g., disabling fields).

T

SchemaOrSchemaFn<T>

The base schema serving as the foundation.

SchemaOrSchemaFn<T>[]

Additional schemas or conditions to be applied to the base schema.

Schema<T>

A new Schema<T> containing all combined conditions.

// Combining multiple schemas
const combinedSchema = compose(MyDefaultSchema, RequiredFieldsSchema, ExtendedSchema);
// Extending a schema with a disable rule
const combinedSchema = compose(MyDefaultSchema, disabled);
// Extending a schema with complex conditions
const combinedSchema = compose(MyDefaultSchema, (fieldPath) => {
disabled(fieldPath.firstname);
hidden(fieldPath.lastname);
});