<T, E extends T = T>(annotations?: Schema.Annotations.Key<T>): Getter<
T,
E
>Creates a getter that fails with MissingKey if the input is absent (Option.None).
When to use
Use when you need a schema getter to require a struct field in the encoded input and report a missing key error when it is absent.
Details
- When input is
None, fails withSchemaIssue.MissingKey. - When input is
Some, passes it through unchanged. - Optional
annotationscustomize the error message for the missing key.
Example (Defining a required struct field)
import { SchemaGetter } from "effect"
const mustExist = SchemaGetter.required<string>()export function function required<T, E extends T = T>(
annotations?: Schema.Annotations.Key<T>
): Getter<T, E>
Creates a getter that fails with MissingKey if the input is absent (Option.None).
When to use
Use when you need a schema getter to require a struct field in the encoded
input and report a missing key error when it is absent.
Details
- When input is
None, fails with SchemaIssue.MissingKey.
- When input is
Some, passes it through unchanged.
- Optional
annotations customize the error message for the missing key.
Example (Defining a required struct field)
import { SchemaGetter } from "effect"
const mustExist = SchemaGetter.required<string>()
required<function (type parameter) T in required<T, E extends T = T>(annotations?: Schema.Annotations.Key<T>): Getter<T, E>T, function (type parameter) E in required<T, E extends T = T>(annotations?: Schema.Annotations.Key<T>): Getter<T, E>E extends function (type parameter) T in required<T, E extends T = T>(annotations?: Schema.Annotations.Key<T>): Getter<T, E>T = function (type parameter) T in required<T, E extends T = T>(annotations?: Schema.Annotations.Key<T>): Getter<T, E>T>(annotations: anyannotations?: import SchemaSchema.declareAnnotations.type Schema.Annotations.Key = /*unresolved*/ anyKey<function (type parameter) T in required<T, E extends T = T>(annotations?: Schema.Annotations.Key<T>): Getter<T, E>T>): class Getter<out T, in E, R = never>class Getter {
run: (input: Option.Option<E>, options: SchemaAST.ParseOptions) => Effect.Effect<Option.Option<T>, SchemaIssue.Issue, R>;
map: <T2>(f: (t: T) => T2) => Getter<T2, E, R>;
compose: <T2, R2>(other: Getter<T2, T, R2>) => Getter<T2, E, R | R2>;
pipe: { <A>(this: A): A; <A, B = never>(this: A, ab: (_: A) => B): B; <A, B = never, C = never>(this: A, ab: (_: A) => B, bc: (_: B) => C): C; <A, B = never, C = never, D = never>(this: A, ab: (_: A) => B, bc: (_: B) => C, cd: (_: C) => D): D; <…;
}
Represents a composable transformation from an encoded type E to a decoded type T.
When to use
Use when you need a schema getter to build and compose custom transformations
for Schema.decodeTo or Schema.decode.
Details
A getter wraps a function Option<E> -> Effect<Option<T>, Issue, R>. It
receives Option.None when the encoded key is absent, such as a missing
struct field, and returns Option.None to omit the value from the decoded
output. It fails with Issue on invalid input and may require Effect
services via R. .map(f) applies f to the decoded value inside Some
while leaving None unchanged. .compose(other) chains two getters by
feeding the output of this into other; passthrough getters on either side
are optimized away.
Example (Creating and composing getters)
import { SchemaGetter } from "effect"
const parseNumber = SchemaGetter.transform<number, string>((s) => Number(s))
const double = SchemaGetter.transform<number, number>((n) => n * 2)
const composed = parseNumber.compose(double)
// composed: Getter<number, string> — parses then doubles
Getter<function (type parameter) T in required<T, E extends T = T>(annotations?: Schema.Annotations.Key<T>): Getter<T, E>T, function (type parameter) E in required<T, E extends T = T>(annotations?: Schema.Annotations.Key<T>): Getter<T, E>E> {
return function onNone<
T,
E extends T = T,
R = never
>(
f: (
options: SchemaAST.ParseOptions
) => Effect.Effect<
Option.Option<T>,
SchemaIssue.Issue,
R
>
): Getter<T, E, R>
Creates a getter that handles the case when the input is absent (Option.None).
When to use
Use when you need a schema getter to provide a fallback or computed value for
missing struct keys.
- Building custom "default value" logic more complex than
withDefault
.
Details
- When input is
None, calls f to produce the result.
- When input is
Some, passes it through unchanged.
f receives the parse options and may return None to keep the value absent.
Example (Providing a default timestamp for a missing field)
import { Effect, Option, SchemaGetter } from "effect"
const withTimestamp = SchemaGetter.onNone<number>(() =>
Effect.succeed(Option.some(Date.now()))
)
onNone(() => import EffectEffect.fail(new import SchemaIssueSchemaIssue.constructor MissingKey(annotations: Schema.Annotations.Key<unknown> | undefined): SchemaIssue.MissingKeyRepresents a schema issue produced when a required key or tuple index is missing from the input.
When to use
Use when you need to detect absent fields in struct/tuple validation.
Details
- Has no
actual value —
getActual
returns Option.none().
annotations may contain a custom messageMissingKey for formatting.
MissingKey(annotations: anyannotations)))
}