The type system

The most famous feature that made TypeScript what it is, is the type system that enables us to leverage a static type checking at compile time. We have already seen the use of types in the previous code examples. It's important to understand that in TypeScript the use of types is optional but highly recommended. As we saw at the beginning of this chapter, the TypeScript compiler breakdown all the types declaration, so the compilation result will be plain JavaScript.

The basic types

TypeScript supports all the basic JavaScript types you expected: Booleans, Numbers, Strings, and Arrays. The following example shows how to use it in code:

// strings let name: string = "bob"; // boolean let isLoggedIn: boolean = true; // number let height: ...

Get Angular 2 Components now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.