(
to: To,
transformation?: {
readonly decode: SchemaGetter.Getter<From["Encoded"], To["Type"], RD>
readonly encode: SchemaGetter.Getter<To["Type"], From["Encoded"], RE>
}
)
| 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( |
no test coverage detected
searching dependent graphs…