Package: effect
Module: SchemaTransformation
Decodes T | undefined into Option<T> and encodes Option.none() back to
undefined.
When to use
Use when you need a schema transformation to convert API fields that use
undefined for absence to Option.
Details
Decoding maps undefined to Option.none() and non-undefined values to
Option.some(value). Encoding maps Option.none() to undefined and
Option.some(value) to value. The transformation is pure and synchronous.
Example (Converting undefined-or values to an Option)
import { Schema, SchemaTransformation } from "effect"
const schema = Schema.UndefinedOr(Schema.String).pipe(
Schema.decodeTo(
Schema.Option(Schema.String),
SchemaTransformation.optionFromUndefinedOr()
)
)
See
optionFromOptionalKeyoptionFromOptionalSignature
declare const optionFromUndefinedOr: <T>() => Transformation<Option.Option<T>, T | undefined>
Since v4.0.0