Thu Jul 12 2018
Features of TypeScript
The TypeScript compiler makes use of type inference to infer types when types are not given. For example, the add method in the code above would be inferred as returning a number even if no return type annotation had been provided. This is based on the static types of left and right being numbers, and the compiler's knowledge that the result of adding two numbers is always a number. However, explicitly declaring the return type allows the compiler to verify correctness.
TypeScript supports ECMAScript 2015 classes that integrate the optional type annotations support.
TypeScript supports generic programming.
Modules and namespaces
TypeScript support for declaration files makes it easier for you to catch problems up front while working with existing libraries such as jQuery.
The ability to define static types is a key feature of TypeScript (and where its name comes from) and one that can help you identify bugs before even running the code. TypeScript supports many types, including primitive types such as string, number, bool, undefined, and null, as well as object literals and more complex types such as HTMLInputElement.
Access Modifiers and Properties
Access modifiers control the accessibility of the members of a class. TypeScript has two access modifiers - public and private. By default the members are public but you can explicitly add a public or private modifier to them.
As your TypeScript code base grows it becomes important to organize classes and interfaces for better maintainability. TypeScript modules allow you to do just that. A module is a container for your code that helps you organize your code in a neat way.
TypeScript allows you to inherit from existing classes. By inheriting classes you can extend their functionality as per your requirement. For example, you may have a class named Person. You can create specialized classes based on the Person class by extending it to the other classes.
Just as TypeScript supports inheritance, it also supports interfaces. You can define an interface and then implement it in one or more classes.
The classes you define in TypeScript can have the constructor. The constructor usually does the job of initializing the object by setting default values to its properties. The constructor can also be overloaded just like a function.