(a: unknown): a is stringChecks whether a value is a string.
Example (Checking for strings)
import { String } from "effect"
import * as assert from "node:assert"
assert.deepStrictEqual(String.isString("a"), true)
assert.deepStrictEqual(String.isString(1), false)export const const isString: Refinement<
unknown,
string
>
Checks whether a value is a string.
Example (Checking for strings)
import { String } from "effect"
import * as assert from "node:assert"
assert.deepStrictEqual(String.isString("a"), true)
assert.deepStrictEqual(String.isString(1), false)
isString: 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