Skip to content

fromRefinement

fromRefinement<A, B>(r): Predicate<A>

Defined in: Core/Predicate.ts:167

Converts a Refinement<A, B> into a Predicate<A>, discarding the compile-time narrowing. Use this when you want to combine a type guard with plain predicates using and, or, or all.

A

B

Refinement<A, B>

Predicate<A>

const isString: Refinement<unknown, string> =
  Refinement.make(x => typeof x === "string");

const isShortString: Predicate<unknown> = pipe(
  Predicate.fromRefinement(isString),
  Predicate.and(x => (x as string).length < 10)
);

isShortString("hi");            // true
isShortString("a very long string that exceeds ten characters");  // false
isShortString(42);              // false