MCPcopy Create free account
hub / github.com/effect-app/libs / encodeTo

Function encodeTo

repos/effect/packages/effect/src/Schema.ts:5523–5535  ·  view source on GitHub ↗
(
  to: To,
  transformation?: {
    readonly decode: SchemaGetter.Getter<From["Encoded"], To["Type"], RD>
    readonly encode: SchemaGetter.Getter<To["Type"], From["Encoded"], RE>
  }
)

Source from the content-addressed store, hash-verified

5521 * When no transformation is provided, `SchemaTransformation.passthrough()` is
5522 * used, so `From["Type"]` must already be compatible with `To["Encoded"]`.
5523 * The resulting schema combines decoding and encoding services from both
5524 * schemas and any custom transformation.
5525 *
5526 * **Gotchas**
5527 *
5528 * In a custom transformation, `decode` maps `From["Type"]` to `To["Encoded"]`
5529 * and is used on the encoding path, while `encode` maps `To["Encoded"]` to
5530 * `From["Type"]` and is used on the decoding path.
5531 *
5532 * **Example** (Transforming strings to numbers with a schema transformation)
5533 *
5534 * ```ts import.meta.vitest
5535 * import { Schema, SchemaGetter } from "effect"
5536 *
5537 * const NumberFromString = Schema.String.pipe(
5538 * Schema.decodeTo(

Callers 2

withDecodingDefaultTypeFunction · 0.85

Calls 1

decodeToFunction · 0.70

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…