control flow analysis

The compiler following every branch, return and throw in your code to work out the narrowest type a variable can have at each line.

In more detail

After if (!param) return, the compiler knows param is truthy for the rest of the function. Early returns, throws, typeof checks and equality comparisons all feed into it. It is what makes narrowing automatic.

Related terms

Taught in

References