Skip to content

attachPropertySignature

const attachPropertySignature: {<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.

<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.

K extends PropertyKey

V extends symbol | LiteralValue

A

K

V

Schema<{ [K in PropertyKey]: (A & { readonly [k in PropertyKey]: V })[K] }, readonly []>

<I, R>(schema): SchemaClass<{ [K in PropertyKey]: (A & { readonly [k in PropertyKey]: V })[K] }, I, R>

I

R

SchemaClass<A, I, R>

SchemaClass<{ [K in PropertyKey]: (A & { readonly [k in PropertyKey]: V })[K] }, I, R>

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

<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.

A

I

R

K extends PropertyKey

V extends symbol | LiteralValue

Schema<A, I, R>

K

V

Schema<{ [K in PropertyKey]: (A & { readonly [k in PropertyKey]: V })[K] }, readonly []>

SchemaClass<{ [K in PropertyKey]: (A & { readonly [k in PropertyKey]: V })[K] }, I, R>

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

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