API Reference / @evolu/common / Types / Refinement

Type Alias: Refinement()<A, B>

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

Defined in: packages/common/src/Types.ts:43

A type guard function that refines type A to a narrower type B.

Example

type Animal = { name: string };
type Dog = Animal & { breed: string };

const isDog: Refinement<Animal, Dog> = (animal): animal is Dog =>
  "breed" in animal;

const animal: Animal = { name: "Dog", breed: "Beagle" };
if (isDog(animal)) {
  console.log(animal.breed); // Safe access to `breed`
}

Type Parameters

Type Parameter
A
B extends A

Parameters

ParameterType
aA

Returns

a is B

Was this page helpful?