<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"
})
)
})export function function annotateKey<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"
})
)
})
annotateKey<function (type parameter) S in annotateKey<S extends Top>(annotations: Annotations.Key<S["Type"]>): (self: S) => S["Rebuild"]S extends Top>(annotations: Annotations.Key<S["Type"]>(parameter) annotations: {
messageMissingKey: string | undefined;
default: T | undefined;
examples: ReadonlyArray<T> | undefined;
expected: string | undefined;
title: string | undefined;
description: string | undefined;
documentation: string | undefined;
readOnly: boolean | undefined;
writeOnly: boolean | undefined;
format: string | undefined;
contentEncoding: string | undefined;
contentMediaType: string | undefined;
}
annotations: Annotations.interface Annotations.Key<T>Annotations for struct property schemas. Extends
Documentation
with an optional messageMissingKey to override the error message when
the property key is absent during decoding.
Key<function (type parameter) S in annotateKey<S extends Top>(annotations: Annotations.Key<S["Type"]>): (self: S) => S["Rebuild"]S["Type"]>) {
return (self: S extends Topself: function (type parameter) S in annotateKey<S extends Top>(annotations: Annotations.Key<S["Type"]>): (self: S) => S["Rebuild"]S): function (type parameter) S in annotateKey<S extends Top>(annotations: Annotations.Key<S["Type"]>): (self: S) => S["Rebuild"]S["Rebuild"] => {
return self: S extends Topself.Bottom<unknown, unknown, unknown, unknown, AST, Top, unknown, unknown, any, unknown, Mutability, Optionality, ConstructorDefault, Mutability, Optionality>.rebuild(ast: S["ast"]): S["Rebuild"]rebuild(import SchemaASTSchemaAST.function annotateKey<A extends AST>(
ast: A,
annotations: Schema.Annotations.Key<unknown>
): A
annotateKey(self: S extends Topself.Bottom<unknown, unknown, unknown, unknown, AST, Top, unknown, unknown, any, unknown, Mutability, Optionality, ConstructorDefault, Mutability, Optionality>["ast"]: SchemaAST.ASTast, annotations: Annotations.Key<S["Type"]>(parameter) annotations: {
messageMissingKey: string | undefined;
default: T | undefined;
examples: ReadonlyArray<T> | undefined;
expected: string | undefined;
title: string | undefined;
description: string | undefined;
documentation: string | undefined;
readOnly: boolean | undefined;
writeOnly: boolean | undefined;
format: string | undefined;
contentEncoding: string | undefined;
contentMediaType: string | undefined;
}
annotations))
}
}