Types in TypeScript

Working with TypeScript or any other coding language means basically working with data, and such data can represent different sorts of content. This is what we know as types, a noun used to represent the fact that such data can be a text string, an integer value, or an array of these value types, among others. This is nothing new to JavaScript, since we have always been working implicitly with types, but in a flexible manner. This means that any given variable could assume (or return, in the case of functions) any type of value. Sometimes, this leads to errors and exceptions in our code because of type collisions between what our code returned and what we expected it to return type-wise. While this flexibility can still be enforced by means of any type that we will see later on in this chapter, statically typing our variables gives us and our IDEs a good picture of what kind of data we are supposed to find on each instance of code. This becomes an invaluable way to help debug our applications at compile time before it's too late. To investigate how a language feature works, I suggest you use a playground for two reasons. The first reason is to learn how the feature works. The second reason is to know the corresponding ES5 code it produces. I suggest using the following playground for this: https://www.typescriptlang.org/play/.

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

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