3 Matching Annotations
- Feb 2023
-
medium.com medium.com
-
The variable x initially has the type unknown: the type of all values. The predicate typeof x === "number" extracts dynamic information about the value bound to x, but the type-checker can exploit this information for static reasoning. In the body of the if statement the predicate is assumed to be true; therefore, it must be the case the value bound to x is a number. TypeScript exploits this information and narrows the type of x from unknown to number in the body of if statement.
-
- Oct 2019
-
microsoft.github.io microsoft.github.io
-
type guards
-