RecipesChapter 3: The Type System

Narrowing Types with Type Predicates

Recipe 3.5 from The TypeScript Cookbook

// Correct on a type-level, incorrect logic
function isDice(value: number): value is Dice {
  return value >= 1 && value <= 6;
}
Open in TypeScript Playground →