<S extends Top>(toFormatter: () => Formatter<S["Type"]>): (
self: S
) => S["Rebuild"]Attaches a custom formatter used by toFormatter.
Details
Use this when the formatter derived from the schema structure is not suitable.
The annotation is applied through this helper because adding it directly to
Annotations.Bottom would make schemas invariant.
export function function overrideToFormatter<
S extends Top
>(
toFormatter: () => Formatter<S["Type"]>
): (self: S) => S["Rebuild"]
Attaches a custom formatter used by toFormatter.
Details
Use this when the formatter derived from the schema structure is not suitable.
The annotation is applied through this helper because adding it directly to
Annotations.Bottom would make schemas invariant.
overrideToFormatter<function (type parameter) S in overrideToFormatter<S extends Top>(toFormatter: () => Formatter<S["Type"]>): (self: S) => S["Rebuild"]S extends Top>(toFormatter: () => Formatter<S["Type"]>toFormatter: () => interface Formatter<in Value, out Format = string>A callable interface representing a function that converts a Value into a Format, which defaults to string.
When to use
Use when you want to type a formatting or rendering function generically, or when you are building a pipeline that accepts pluggable formatters.
Details
This is a pure callable type and carries no runtime implementation. It is contravariant in Value and covariant in Format.
Example (Defining a custom formatter)
import type { Formatter } from "effect"
const upper: Formatter.Formatter<string> = (s) => s.toUpperCase()
console.log(upper("hello"))
// HELLO
Formatter<function (type parameter) S in overrideToFormatter<S extends Top>(toFormatter: () => Formatter<S["Type"]>): (self: S) => S["Rebuild"]S["Type"]>) {
return (self: S extends Topself: function (type parameter) S in overrideToFormatter<S extends Top>(toFormatter: () => Formatter<S["Type"]>): (self: S) => S["Rebuild"]S): function (type parameter) S in overrideToFormatter<S extends Top>(toFormatter: () => Formatter<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>.annotate(annotations: Annotations.Bottom<S["Type"], S["~type.parameters"]>): S["Rebuild"]annotate({ toFormatter: () => Formatter<S["Type"]>toFormatter })
}
}