Appendix B. TypeScript as a language for Angular applications


You may be wondering, why not just develop in JavaScript? Why do we need to use other programming languages if JavaScript is already a language? You wouldn’t find articles about languages for developing Java or C# applications, would you?

The reason is that developing in JavaScript isn’t overly productive. Say a function expects a string value as an argument, but the developer mistakenly invokes it by passing a numeric value. With JavaScript, this error can be caught only at runtime. Java or C# compilers won’t even compile code that has mismatching types, but JavaScript is forgiving because it’s a dynamically typed language.

Although JavaScript engines do a good job of guessing the types of variables by their values, development tools have a limited ability to help you without knowing the types. In mid- and large-size applications, this JavaScript shortcoming lowers the productivity of software developers.

On larger projects, good IDE context-sensitive help and support for refactoring are important. Renaming all occurrences of a variable or function name in statically typed languages is done by IDEs in a split second, even in projects that have thousands of lines of code; but this isn’t the case in JavaScript, which doesn’t support types. IDEs can help with refactoring much better when the types of the variables are known.

B.1. Why write Angular apps in TypeScript?

B.2. The role of transpilers

B.3. Getting started with TypeScript

B.4. TypeScript as a superset of JavaScript

B.5. Optional types

B.6. Classes

B.7. Generics

B.8. Interfaces

B.9. Adding class metadata with annotations

B.10. Type-definition files

B.11. An overview of the TypeScript/Angular development process