(u: unknown): u is RedactableType guard that checks whether a value implements the Redactable interface.
When to use
Use to narrow an unknown value before calling redaction-specific helpers.
export const const isRedactable: (
u: unknown
) => u is Redactable
Type guard that checks whether a value implements the
Redactable
interface.
When to use
Use to narrow an unknown value before calling redaction-specific helpers.
isRedactable = (u: unknownu: unknown): u: unknownu is Redactable => hasProperty<typeof symbolRedactable>(self: unknown, property: typeof symbolRedactable): self is { [K in typeof symbolRedactable]: unknown; } (+1 overload)Checks whether a value has a given property key.
When to use
Use when you need a Predicate guard for property access on unknown
values with a simple structural object check.
Details
Uses the in operator and isObjectKeyword. This does not check property
value types.
Example (Guarding object properties)
import { Predicate } from "effect"
const hasName = Predicate.hasProperty("name")
const data: unknown = { name: "Ada" }
if (hasName(data)) {
console.log(data.name)
}
hasProperty(u: unknownu, const symbolRedactable: typeof symbolRedactableDefines the symbol used to identify objects that implement the
Redactable
protocol.
When to use
Use as the property key when implementing the Redactable protocol.
Details
Add a method under this key to make an object redactable. The method receives
the current Context and must return the replacement value. The symbol is
registered globally via Symbol.for("~effect/Redactable"), so it is
identical across multiple copies of the library at runtime.
Example (Masking an API key)
import { Context, Redactable } from "effect"
class ApiKey {
constructor(readonly raw: string) {}
[Redactable.symbolRedactable](_ctx: Context.Context<never>) {
return this.raw.slice(0, 4) + "..."
}
}
symbolRedactable)