Package: effect
Module: Schema
Extends a schema with another schema.
Not all extensions are supported, and their support depends on the nature of the involved schemas.
Possible extensions include:
Schema.String with another Schema.String refinement or a string literalSchema.Number with another Schema.Number refinement or a number literalSchema.Boolean with another Schema.Boolean refinement or a boolean
literalExample
import * as Schema from "effect/Schema"
const schema = Schema.Struct({
a: Schema.String,
b: Schema.String
})
// const extended: Schema<
// {
// readonly a: string
// readonly b: string
// } & {
// readonly c: string
// } & {
// readonly [x: string]: string
// }
// >
const extended = Schema.asSchema(schema.pipe(
Schema.extend(Schema.Struct({ c: Schema.String })), // <= you can add more fields
Schema.extend(Schema.Record({ key: Schema.String, value: Schema.String })) // <= you can add index signatures
))
Signature
declare const extend: { <That extends Schema.Any>(that: That): <Self extends Schema.Any>(self: Self) => extend<Self, That>; <Self extends Schema.Any, That extends Schema.Any>(self: Self, that: That): extend<Self, That>; }
Since v3.10.0