narrowing は、TypeScript が(union のような)広い型を、ランタイムのチェックに基づいてコードの分岐内でより具体的な型へと絞り込む仕組みです。コンパイラは制御フローを追跡し、それに応じて型を更新します。
ts
function process(x: string | number) {
if (typeof x === "string") {
x.toUpperCase(); // ✅ here x is narrowed to string
} else {
x.();
}
}
