December 2017
Beginner
372 pages
10h 32m
English
TypeScript provides type analysis based on the code flow. Types can be narrowed or broadened based on the code flow. This helps to reduce logical errors when we have multiple types of a variable and logic varies with type as shown in the following code:
function projectStatus (x: string | number) { if (typeof x === 'string') { // x is string | number x = 10; } return x; // type of `number}
TypeScript by code flow analysis determined that the type of x returned from the function is a number.
Read now
Unlock full access