attachPropertySignature
constattachPropertySignature: {<K,V,A>(key,value,annotations?): <I,R>(schema) =>SchemaClass<{ [K in PropertyKey]: (A & { readonly [k in PropertyKey]: V })[K] },I,R>; <A,I,R,K,V>(schema,key,value,annotations?):SchemaClass<{ [K in PropertyKey]: (A & { readonly [k in PropertyKey]: V })[K] },I,R>; }
Defined in: node_modules/.pnpm/effect@3.15.2/node_modules/effect/dist/dts/Schema.d.ts:2105
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.
Call Signature
Section titled “Call Signature”<
K,V,A>(key,value,annotations?): <I,R>(schema) =>SchemaClass<{ [K in PropertyKey]: (A & { readonly [k in PropertyKey]: V })[K] },I,R>
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.
Type Parameters
Section titled “Type Parameters”K extends PropertyKey
V extends symbol | LiteralValue
A
Parameters
Section titled “Parameters”K
V
annotations?
Section titled “annotations?”Schema<{ [K in PropertyKey]: (A & { readonly [k in PropertyKey]: V })[K] }, readonly []>
Returns
Section titled “Returns”<
I,R>(schema):SchemaClass<{ [K in PropertyKey]: (A & { readonly [k in PropertyKey]: V })[K] },I,R>
Type Parameters
Section titled “Type Parameters”I
R
Parameters
Section titled “Parameters”schema
Section titled “schema”SchemaClass<A, I, R>
Returns
Section titled “Returns”SchemaClass<{ [K in PropertyKey]: (A & { readonly [k in PropertyKey]: V })[K] }, I, R>
Example
Section titled “Example”import * as assert from "node:assert"import * as S from "effect/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})3.10.0
Call Signature
Section titled “Call Signature”<
A,I,R,K,V>(schema,key,value,annotations?):SchemaClass<{ [K in PropertyKey]: (A & { readonly [k in PropertyKey]: V })[K] },I,R>
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.
Type Parameters
Section titled “Type Parameters”A
I
R
K extends PropertyKey
V extends symbol | LiteralValue
Parameters
Section titled “Parameters”schema
Section titled “schema”Schema<A, I, R>
K
V
annotations?
Section titled “annotations?”Schema<{ [K in PropertyKey]: (A & { readonly [k in PropertyKey]: V })[K] }, readonly []>
Returns
Section titled “Returns”SchemaClass<{ [K in PropertyKey]: (A & { readonly [k in PropertyKey]: V })[K] }, I, R>
Example
Section titled “Example”import * as assert from "node:assert"import * as S from "effect/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})3.10.0
Example
Section titled “Example”import * as assert from "node:assert"import * as S from "effect/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})3.10.0