Skip to content

Refinement

Refinement<A, B> = (a) => a is B

Defined in: Core/Refinement.ts:26

A function from A to A is B — a type predicate paired with a runtime check.

A Refinement<A, B> proves at compile time that a value of type A is actually the narrower type B extends A, backed by a runtime boolean test. Use it to express domain invariants (non-empty strings, positive numbers, valid emails) as first-class, composable values rather than one-off type guards scattered across the codebase.

A

B extends A

A

a is B

type NonEmptyString = string & { readonly _tag: "NonEmptyString" };

const isNonEmpty: Refinement<string, NonEmptyString> =
  Refinement.make(s => s.length > 0);

pipe(
  "hello",
  Refinement.toFilter(isNonEmpty)
); // Some("hello")