Typescript

Typescript is an open-source, object-oriented programming language that is developed and maintained by Microsoft and serves as a superset of Javascript.

Typescript code does not directly run on the browser. The browser does not understand newer versions of Javascript code.

so It needs a compiler to compile Typescript code and generate javascript code and a babel transpiler to transpile javascript code into plain Javascript code so that the browser can understand. Typescript is the ES6 version of Javascript with some additional features.

It adds static typing, robustness and other features to the Javascript language, allowing developers to catch errors early in the development process and enhance code quality.

Typescript code is eventually compiled to standard Javascript, making it compatible with any Javascript runtime.

Typescript Key Features

  • Type Checking: Typescript allows us to define types for variables, function parameters, and return values, enabling early error detection and improved code quality.

  • Enums: Typescript provides a way to define an enum (enumeration) named constants, an enum used to create a set of distinct constant attributes. Enums are useful when we have a small set of related values that are known at compile time.

  • Tuples: Typescript provides a way to define a tuple as an array-like structure where each element represents a fixed type. Unlike arrays, the number of elements in a tuple is fixed, and each element's type is known.

  • Classes: Typescript supports object-oriented programming principles like classes, inheritance, abstraction, polymorphism, encapsulation and access modifiers, making it easier to organize and reuse code.

  • Generics: Typescript allows us to create reusable components and methods that can work with various data types.

  • Compilation: Compiling Typescript involves converting Typescript code (.ts files) into plain Javascript code (.js files) that can be executed by browsers. The Typescript compiler `tsc` is responsible for this task.

  • Supported by Major Frameworks: Typescript provides support to the majority of popular programming languages for ex: C, Java, Next.js.

  • Interface: Typescript allows us a way to define the shape of an object, making it easier to work with complex data structures and reuse code.

  • Advanced Type Features: Typescript offers advanced type features like intersection types, union types, type aliases, and more, allowing us to express complex data types and constraints in code.

  • Modules: Typescript supports ES6 modules, enabling us to organize our code into reusable and maintainable modules with the latest features of ES6 modules.