SafeRefinement<unknown, any>Matches any value without restrictions.
When to use
Use to define an explicit catch-all pattern when the handler should receive the unmatched value.
Details
This predicate matches every input, including undefined, null, objects,
primitives, and functions.
Gotchas
Match.any should usually be last because cases are checked in order and
the first matching case wins.
Example (Matching any remaining value)
import { Match } from "effect"
const describeValue = Match.type<unknown>()
.pipe(
Match.when(Match.string, (str) => `String: ${str}`),
Match.when(Match.number, (num) => `Number: ${num}`),
Match.when(Match.boolean, (bool) => `Boolean: ${bool}`),
Match.when(Match.any, (value) => `Other: ${typeof value}`),
Match.exhaustive
)
console.log(describeValue("hello"))
// Output: "String: hello"
console.log(describeValue(42))
// Output: "Number: 42"
console.log(describeValue([1, 2, 3]))
// Output: "Other: object"
console.log(describeValue(null))
// Output: "Other: object"export const const any: SafeRefinement<unknown, any>Matches any value without restrictions.
When to use
Use to define an explicit catch-all pattern when the handler should receive
the unmatched value.
Details
This predicate matches every input, including undefined, null, objects,
primitives, and functions.
Gotchas
Match.any should usually be last because cases are checked in order and
the first matching case wins.
Example (Matching any remaining value)
import { Match } from "effect"
const describeValue = Match.type<unknown>()
.pipe(
Match.when(Match.string, (str) => `String: ${str}`),
Match.when(Match.number, (num) => `Number: ${num}`),
Match.when(Match.boolean, (bool) => `Boolean: ${bool}`),
Match.when(Match.any, (value) => `Other: ${typeof value}`),
Match.exhaustive
)
console.log(describeValue("hello"))
// Output: "String: hello"
console.log(describeValue(42))
// Output: "Number: 42"
console.log(describeValue([1, 2, 3]))
// Output: "Other: object"
console.log(describeValue(null))
// Output: "Other: object"
any: interface SafeRefinement<in A, out R = A>A safe refinement that narrows types without runtime errors.
Details
SafeRefinement provides a way to refine types in pattern matching while
maintaining type safety. Unlike regular predicates, safe refinements can
transform the matched value's type without throwing runtime errors.
Example (Using safe refinements)
import { Match } from "effect"
// Built-in safe refinements
const processValue = Match.type<unknown>().pipe(
Match.when(Match.string, (s) => s.toUpperCase()),
Match.when(Match.number, (n) => n * 2),
Match.when(Match.defined, (value) => `Defined: ${value}`),
Match.orElse(() => "Undefined or null")
)
console.log(processValue("hello")) // "HELLO"
console.log(processValue(21)) // 42
console.log(processValue(true)) // "Defined: true"
console.log(processValue(null)) // "Undefined or null"
SafeRefinement<unknown, any> = import internalinternal.const any: SafeRefinement<unknown, any>any