(a: unknown): a is bigintMatches values of type bigint.
When to use
Use to match primitive bigint values.
Details
This predicate refines unknown values to bigints, allowing pattern matching on bigint types. BigInts are used for representing integers with arbitrary precision.
Example (Matching bigint values)
import { Match } from "effect"
const processLargeNumber = Match.type<unknown>().pipe(
Match.when(Match.bigint, (big) => {
if (big > 9007199254740991n) {
return `Large integer: ${big.toString()}`
}
return `BigInt: ${big.toString()}`
}),
Match.when(Match.number, (num) => `Regular number: ${num}`),
Match.orElse(() => "Not a numeric type")
)
console.log(processLargeNumber(123n)) // "BigInt: 123"
console.log(processLargeNumber(9007199254740992n)) // "Large integer: 9007199254740992"
console.log(processLargeNumber(123)) // "Regular number: 123"
console.log(processLargeNumber("123")) // "Not a numeric type"export const const bigint: Predicate.Refinement<
unknown,
bigint
>
Matches values of type bigint.
When to use
Use to match primitive bigint values.
Details
This predicate refines unknown values to bigints, allowing pattern matching
on bigint types. BigInts are used for representing integers with arbitrary precision.
Example (Matching bigint values)
import { Match } from "effect"
const processLargeNumber = Match.type<unknown>().pipe(
Match.when(Match.bigint, (big) => {
if (big > 9007199254740991n) {
return `Large integer: ${big.toString()}`
}
return `BigInt: ${big.toString()}`
}),
Match.when(Match.number, (num) => `Regular number: ${num}`),
Match.orElse(() => "Not a numeric type")
)
console.log(processLargeNumber(123n)) // "BigInt: 123"
console.log(processLargeNumber(9007199254740992n)) // "Large integer: 9007199254740992"
console.log(processLargeNumber(123)) // "Regular number: 123"
console.log(processLargeNumber("123")) // "Not a numeric type"
bigint: 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, bigint> = import PredicatePredicate.function isBigInt(
input: unknown
): input is bigint
Checks whether a value is a bigint.
When to use
Use when you need a Predicate guard to narrow an unknown value to a
bigint.
Details
Uses typeof input === "bigint".
Example (Guarding bigints)
import { Predicate } from "effect"
const data: unknown = 1n
if (Predicate.isBigInt(data)) {
console.log(data + 2n)
}
isBigInt