October 2017
Intermediate to advanced
280 pages
6h 50m
English
All the types in TypeScript are subtypes of a type called any. We can declare variables belonging to the any type using the any keyword. Such variables can hold the value of any type:
let foo: any;
foo = {};
foo = 'bar ';
foo += 42;
console.log(foo); // "bar 42"
The preceding code is a valid TypeScript, and it will not throw any error during compilation or runtime. If we use the any type for all of our variables, we will be basically writing the code with dynamic typing, which drops all the benefits of the TypeScript's compiler. This is why we have to be careful with any and use it only when it is necessary.
Other types in TypeScript that we will take a look at are as follows:
Read now
Unlock full access