Narrowing is how TypeScript lets you use the right methods on the right type.
Direct answer
A type guard is a runtime check that narrows a type within a block. Built-in guards include typeof, instanceof, in and equality checks. You can write custom guards with a type predicate such as value is Cat.
Built-in guards
function format(x: string | number | Date) {
if (typeof x === "string") return x.trim();
if (typeof x === "number") return x.toFixed(1);
if (x instanceof Date) return x.toISOString();
}
type Fish = { swim: () => void };
type Bird = { fly: () => void };
function move(animal: Fish | Bird) {
if ("swim" in animal) animal.swim();
else animal.fly();
}
Custom type guard
function isString(value: unknown): value is string {
return typeof value === "string";
}
Where Teyro fits
Teyro's TypeScript for Beginners course turns this into short lessons you can play in a few minutes a day. It has 20 lessons, and you can start free.
The bottom line
Check, then use. TypeScript follows your checks.


