(a: unknown): a is numberMatches values of type number.
When to use
Use to match primitive number values, including NaN and infinities.
Details
This predicate refines unknown values to numbers, allowing pattern matching
on numeric types. It matches all number values including integers, floats,
Infinity, -Infinity, and NaN.
Example (Matching number values)
import { Match } from "effect"
const categorizeNumber = Match.type<unknown>().pipe(
Match.when(Match.number, (num) => {
if (Number.isNaN(num)) return "Not a number"
if (!Number.isFinite(num)) return "Infinite"
if (Number.isInteger(num)) return `Integer: ${num}`
return `Float: ${num.toFixed(2)}`
}),
Match.orElse(() => "Not a number type")
)
console.log(categorizeNumber(42)) // "Integer: 42"
console.log(categorizeNumber(3.14)) // "Float: 3.14"
console.log(categorizeNumber(NaN)) // "Not a number"
console.log(categorizeNumber("hello")) // "Not a number type"export const const number: Predicate.Refinement<
unknown,
number
>
Matches values of type number.
When to use
Use to match primitive number values, including NaN and infinities.
Details
This predicate refines unknown values to numbers, allowing pattern matching
on numeric types. It matches all number values including integers, floats,
Infinity, -Infinity, and NaN.
Example (Matching number values)
import { Match } from "effect"
const categorizeNumber = Match.type<unknown>().pipe(
Match.when(Match.number, (num) => {
if (Number.isNaN(num)) return "Not a number"
if (!Number.isFinite(num)) return "Infinite"
if (Number.isInteger(num)) return `Integer: ${num}`
return `Float: ${num.toFixed(2)}`
}),
Match.orElse(() => "Not a number type")
)
console.log(categorizeNumber(42)) // "Integer: 42"
console.log(categorizeNumber(3.14)) // "Float: 3.14"
console.log(categorizeNumber(NaN)) // "Not a number"
console.log(categorizeNumber("hello")) // "Not a number type"
number: 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, number> = import PredicatePredicate.function isNumber(
input: unknown
): input is number
Checks whether a value is a number.
When to use
Use when you need a Predicate guard to narrow an unknown value to a
number.
Details
Uses typeof input === "number" and does not exclude NaN or Infinity.
Example (Guarding numbers)
import { Predicate } from "effect"
const data: unknown = 42
if (Predicate.isNumber(data)) {
console.log(data + 1)
}
isNumber