Hyperlinkv0.8.0-beta.28

Schema

Schema.annotateKeyfunctioneffect/Schema.ts:605
<S extends Top>(annotations: Annotations.Key<S["Type"]>): (
  self: S
) => S["Rebuild"]

Adds key-level annotations to a schema field. This is the pipeable (curried) counterpart of the .annotateKey method.

Details

Key annotations apply to a field's position inside a Struct or Tuple rather than to the field's value type. They can carry a messageMissingKey to customise the error shown when the field is absent, as well as standard documentation fields such as title, description, and examples.

Example (Customizing the missing-key message for a required field)

import { Schema } from "effect"

const schema = Schema.Struct({
  username: Schema.String.pipe(
    Schema.annotateKey({
      description: "The username used to log in",
      messageMissingKey: "Username is required"
    })
  )
})
annotations
Source effect/Schema.ts:6055 lines
export function annotateKey<S extends Top>(annotations: Annotations.Key<S["Type"]>) {
  return (self: S): S["Rebuild"] => {
    return self.rebuild(SchemaAST.annotateKey(self.ast, annotations))
  }
}