Import
import { Guard } from "@typed/guard";Signatures
export type Guard<in I, out O, out E = never, out R = never> = (input: I) => Effect.Effect<Option.Option<O>, E, R>;export declare namespace Guard {
type Input<T> = [
T
] extends [
Guard<infer I, infer _R, infer _E, infer _O>
] ? I : [
T
] extends [
AsGuard<infer I, infer _R, infer _E, infer _O>
] ? I : never;
type Services<T> = [
T
] extends [
Guard<infer _I, infer _O, infer _E, infer R>
] ? R : [
T
] extends [
AsGuard<infer _I, infer _O, infer _E, infer R>
] ? R : never;
type Error<T> = [
T
] extends [
Guard<infer _I, infer _O, infer E, infer _R>
] ? E : [
T
] extends [
AsGuard<infer _I, infer _O, infer E, infer _R>
] ? E : never;
type Output<T> = [
T
] extends [
Guard<infer _I, infer O, infer _E, infer _R>
] ? O : [
T
] extends [
AsGuard<infer _I, infer O, infer _E, infer _R>
] ? O : never;
}Why
Guard models non-match as successful None, keeping ordinary dispatch separate from typed failure, defects, and interruption in Effect’s Cause.
Ownership and lifetime
A Guard acquires no resources by itself; each invocation has the lifetime and service requirements of the returned Effect.
See Effect Option and Effect error management.
Examples
import type { Guard } from "@typed/guard"
import { Effect, Option } from "effect"
const string: Guard<unknown, string> = (input) => Effect.succeed(typeof input === "string" ? Option.some(input) : Option.none())Members
Guard.ErrorExtracts the typed error channel from a Guard or Guard adapter.
Guard.InputExtracts the accepted input type from a Guard or Guard adapter.
Guard.OutputExtracts the matched output type from a Guard or Guard adapter.
Guard.ServicesExtracts the Effect service requirements from a Guard or Guard adapter.
Other public imports
These import paths expose the same declaration. Each page retains its own public name and signature.