Angular - 1.6 What is Typescript?

In the previous lesson we worked with files ending in .ts. This extension stands for TypeScript and it deserves a dedicated introduction because it plays a central role inside the Angular framework. Angular was designed to work hand in hand with TypeScript, and this choice is not accidental: the framework focuses on robustness and structure, the Angular CLI generates folders, sub-folders and files for us, and TypeScript brings the same philosophy at the language level by reducing human errors.

It is worth underlining that TypeScript is not actually part of Angular. It is an open-source language created by Microsoft that can be used outside of Angular too. Other libraries also accept TypeScript, but they make it optional. The fact that Angular adopts TypeScript by default reflects a convergence in programming philosophy around robustness.

What TypeScript adds to JavaScript

  • Static typing: variables get an explicit type at declaration, like in Java or C.
  • Interfaces: define the shape of objects to architect code more cleanly.
  • Classes: enhanced syntax beyond what plain ECMAScript 6 offers.
  • Compile-time checks: the compiler catches mistakes before the code reaches the browser.

Everything that is valid in JavaScript is valid in TypeScript: it is a superset that simply adds extra features. The most important addition is typing. Scripting languages like PHP, Python, Ruby and JavaScript use implicit typing: the type of a variable is determined dynamically at execution time. In a JavaScript example, assigning a string to a variable and then an integer on the next line will not produce an error, but it makes the code harder to reason about. In TypeScript, declaring the variable explicitly as a string will trigger a red underline as soon as you try to assign an integer.

Browsers cannot execute TypeScript directly. The Angular CLI takes care of compiling it down to plain JavaScript that any browser can understand. To finish on a positive note: you do not need to be a TypeScript specialist to follow this course. If you are comfortable with JavaScript, you will pick up the TypeScript concepts along the way without effort.

Summary

This lesson introduces TypeScript as the core language framework for Angular development. It explains that TypeScript is a Microsoft open-source technology, not part of Angular itself, but crucial to the framework's philosophy of building robust applications. The lesson contrasts JavaScript's implicit typing with TypeScript's explicit type system, demonstrating how TypeScript catches errors at compile time that would slip through in plain JavaScript.

Key points

  • TypeScript is a superset of JavaScript that adds explicit typing, allowing developers to catch errors at compile time rather than runtime
  • Angular was designed to work with TypeScript by default, reflecting a shared commitment to code robustness and application reliability
  • TypeScript supports features like interfaces and strong typing, which JavaScript only partially provides through ES6 classes
  • TypeScript must be compiled to JavaScript before browsers can execute it, a process handled by the Angular CLI
  • JavaScript uses implicit typing (types defined dynamically at runtime), while TypeScript requires explicit type declarations that prevent variables from changing types unpredictably
  • No prior TypeScript expertise is required to follow the Angular course—basic JavaScript knowledge is sufficient to grasp TypeScript concepts gradually

FAQ

Is TypeScript part of Angular, or is it a separate technology?

TypeScript is a separate, open-source technology created by Microsoft. While it is not part of Angular itself, Angular was designed to work with TypeScript by default due to shared principles around code robustness and structured application development.

Why does TypeScript use explicit typing instead of allowing implicit types like JavaScript?

Explicit typing catches errors at compile time, preventing bugs that could occur when a variable inadvertently changes type. This makes code more predictable, easier to understand, and reduces the risk of runtime errors.

Do I need to be a TypeScript expert to learn Angular?

No. If you are comfortable with JavaScript, you will have no difficulty learning TypeScript concepts incrementally as you progress through the Angular course.