Type Guards

This lesson introduces the concept of type guards.

Overview

Type guard is not really a type so much as it is a mechanism that narrows types.

TypeScript soars at analyzing your code and deducing information based on it. Oftentimes, TypeScript can analyze a conditional expression (or an if statement) and narrow the type of the tested value inside the branches of the condition. We’ve already seen this happen with discriminated unions. ...