Types

One of the key features of TypeScript is bringing static typing to JavaScript. In TypeScript, you annotate your code with type information; every declaration can be defined with its associated typing.

In the declaration, you do that by adding a colon following the type. For example, the following statement defines a variable of type number:

const productsCount: number;

Annotating your code with type information enables validation. The TypeScript compiler should throw errors if you try to do anything that is not supported by the specified type, thus productivity and discoverability benefit substantially through type safety. Additionally, with proper tooling support, you get IntelliSense support and automatic code completion.

TypeScript supports a handful of types to reflect most constructs in JavaScript. We will cover these next, starting with basic types.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.138.35.255