Chapter 2. Types, Variables, and Function Techniques

TypeScript introduces strong typing to JavaScript through a simple syntax, referred to by Anders Hejlsberg as "syntactic sugar". This "sugar" is what assigns a type to a variable, a function parameter, or even the return type of a function itself. As we discussed in Chapter 1, TypeScript - Tools and Framework Options, the benefits of strong typing include better error checking, the ability for an IDE to provide more intelligent code suggestions, and the ability to introduce object-oriented techniques into the JavaScript coding experience. There are a number of basic types that the language uses, such as number, string and boolean, to name a few. There are also rules by which the TypeScript compiler ...

Get Mastering TypeScript - Second Edition now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.