attachPropertySignature
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.
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})
Since
3.10.0
Call Signature
attachPropertySignature<
K
,V
,A
>(key
,value
,annotations
?): <I
,R
>(schema
) =>SchemaClass
<{ [K in PropertyKey]: (A & { readonly [k in PropertyKey]: V })[K] }
,I
,R
>
Defined in: node_modules/.pnpm/effect@3.14.8/node_modules/effect/dist/dts/Schema.d.ts:2133
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
• K extends PropertyKey
• V extends symbol
| LiteralValue
• A
Parameters
key
K
value
V
annotations?
Schema
<{ [K in PropertyKey]: (A & { readonly [k in PropertyKey]: V })[K] }
, readonly []>
Returns
Function
Type Parameters
• I
• R
Parameters
schema
SchemaClass
<A
, I
, R
>
Returns
SchemaClass
<{ [K in PropertyKey]: (A & { readonly [k in PropertyKey]: V })[K] }
, I
, R
>
Examples
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})
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})
Since
3.10.0
Since
3.10.0
Call Signature
attachPropertySignature<
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.14.8/node_modules/effect/dist/dts/Schema.d.ts:2165
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
• A
• I
• R
• K extends PropertyKey
• V extends symbol
| LiteralValue
Parameters
schema
Schema
<A
, I
, R
>
key
K
value
V
annotations?
Schema
<{ [K in PropertyKey]: (A & { readonly [k in PropertyKey]: V })[K] }
, readonly []>
Returns
SchemaClass
<{ [K in PropertyKey]: (A & { readonly [k in PropertyKey]: V })[K] }
, I
, R
>
Examples
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})
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})
Since
3.10.0
Since
3.10.0