(a: unknown): a is stringMatches values of type string.
Details
This predicate refines unknown values to strings, allowing pattern matching on string types. It's commonly used in type-based matchers to handle string cases.
Example (Matching string values)
import { Match } from "effect"
const processValue = Match.type<string | number | boolean>().pipe(
Match.when(Match.string, (str) => `String: ${str.toUpperCase()}`),
Match.when(Match.number, (num) => `Number: ${num * 2}`),
Match.when(Match.boolean, (bool) => `Boolean: ${bool ? "yes" : "no"}`),
Match.exhaustive
)
console.log(processValue("hello")) // "String: HELLO"
console.log(processValue(42)) // "Number: 84"
console.log(processValue(true)) // "Boolean: yes"export const const string: Predicate.Refinement<
unknown,
string
>
Matches values of type string.
Details
This predicate refines unknown values to strings, allowing pattern matching
on string types. It's commonly used in type-based matchers to handle string cases.
Example (Matching string values)
import { Match } from "effect"
const processValue = Match.type<string | number | boolean>().pipe(
Match.when(Match.string, (str) => `String: ${str.toUpperCase()}`),
Match.when(Match.number, (num) => `Number: ${num * 2}`),
Match.when(Match.boolean, (bool) => `Boolean: ${bool ? "yes" : "no"}`),
Match.exhaustive
)
console.log(processValue("hello")) // "String: HELLO"
console.log(processValue(42)) // "Number: 84"
console.log(processValue(true)) // "Boolean: yes"
string: import PredicatePredicate.interface Refinement<in A, out B extends A>A predicate that also narrows the input type when it returns true.
When to use
Use when you want a runtime check that refines A to B for TypeScript,
especially when composing type guards with
compose
or safely
checking unknown values.
Details
A refinement returns a type predicate (a is B). Use it with if or
filter to narrow types.
Example (Narrowing unknown values)
import { Predicate } from "effect"
const isString: Predicate.Refinement<unknown, string> = (u): u is string => typeof u === "string"
const data: unknown = "hello"
if (isString(data)) {
console.log(data.toUpperCase())
}
Type-level utilities for working with
Refinement
types.
When to use
Use when you need to extract input and output types from refinement
signatures while writing generic helpers over refinements.
Details
These utilities are type-only, create no runtime values, and the namespace is
erased at runtime.
Example (Extracting refinement types)
import { Predicate } from "effect"
type IsString = Predicate.Refinement<unknown, string>
type Input = Predicate.Refinement.In<IsString>
type Output = Predicate.Refinement.Out<IsString>
Refinement<unknown, string> = import PredicatePredicate.function isString(
input: unknown
): input is string
Checks whether a value is a string.
When to use
Use when you need a Predicate guard to narrow an unknown value to a
string.
Details
Uses typeof input === "string".
Example (Guarding strings)
import { Predicate } from "effect"
const data: unknown = "hi"
if (Predicate.isString(data)) {
console.log(data.toUpperCase())
}
isString