In Chapter 1, Getting Started with TypeScript, we wrote our first TypeScript application and briefly glanced at the static type system. Two variables were created and were given static type annotations to declare them as string objects. These type annotations put a specific set of constraints on the variables being created. These constraints allow the compiler and development tools to better assist in the proper use of the object. This includes a list of functions, variables, and properties available on the object. If a variable is created and no type is provided for it, TypeScript will attempt to infer the type from the context in which it is used. For instance, in the following code, we do not explicitly declare the variable
string; however, since it is created with an initial value, TypeScript is able to infer that it should always be treated as a string:
var hello = "Hello There";
The ability of TypeScript to do this contextual typing provides development tools with the...