The name of the property to add to the schema.
The value of the property to add to the schema.
import * as S from "@effect/schema/Schema"
import { pipe } from "effect/Function"
const Circle = S.struct({ radius: S.number })
const Square = S.struct({ sideLength: S.number })
const Shape = S.union(
Circle.pipe(S.attachPropertySignature("kind", "circle")),
Square.pipe(S.attachPropertySignature("kind", "square"))
)
assert.deepStrictEqual(S.decodeSync(Shape)({ radius: 10 }), {
kind: "circle",
radius: 10
})
1.0.0
Attaches a property signature with the specified key and value to the schema. This API is useful when you want to add a property to your schema which doesn't describe the shape of the input, but rather maps to another schema, for example when you want to add a discriminant to a simple union.
The name of the property to add to the schema.
The value of the property to add to the schema.
import * as S from "@effect/schema/Schema"
import { pipe } from "effect/Function"
const Circle = S.struct({ radius: S.number })
const Square = S.struct({ sideLength: S.number })
const Shape = S.union(
Circle.pipe(S.attachPropertySignature("kind", "circle")),
Square.pipe(S.attachPropertySignature("kind", "square"))
)
assert.deepStrictEqual(S.decodeSync(Shape)({ radius: 10 }), {
kind: "circle",
radius: 10
})
1.0.0
Attaches a property signature with the specified key and value to the schema. This API is useful when you want to add a property to your schema which doesn't describe the shape of the input, but rather maps to another schema, for example when you want to add a discriminant to a simple union.