What is TypeScript?

 What is Type Script


what is typescript

TypeScript is an open-source programming language developed and maintained by Microsoft.Type Script is designed for development of large applications and transcompiles to JavaScript. As TypeScript is a superset of JavaScript, existing JavaScript programs are also valid TypeScript programs.


TypeScript may be used to develop JavaScript applications for both client-side and server-side execution (as with Node.Js or Deno). There are multiple options available for trans compilation.


Compatibility with JavaScript-

TypeScript is a strict superset of ECMAScript 2015, which is itself a superset of ECMAScript 5, commonly referred to as JavaScript.As such, a JavaScript program is also a valid TypeScript program, and a TypeScript program can seamlessly consume JavaScript. By default the compiler targets ECMAScript 5, the current prevailing standard, but is also able to generate constructs used in ECMAScript 3 or 2015.

With TypeScript, it is possible to use existing JavaScript code, incorporate popular JavaScript libraries, and call TypeScript-generated code from other JavaScript. Type declarations for these libraries are provided with the source code.

Type annotations

TypeScript provides static typing through type annotations to enable type checking at compile time. This is optional and can be ignored to use the regular dynamic typing of JavaScript.

function add(left: number, right: number): number {
	return left + right;
}

The annotations for the primitive types are numberboolean and string. Weakly- or dynamically-typed structures are of type any.


Classes

TypeScript supports ECMAScript 2015 classes that integrate the optional type annotations support.

class Person {
    private name: string;
    private age: number;
    private salary: number;

    constructor(name: string, age: number, salary: number) {
        this.name = name;
        this.age = age;
        this.salary = salary;
    }

    toString(): string {
        return `${this.name} (${this.age}) (${this.salary})`; // As of version 1.4
    }
}

Generics

TypeScript supports generic programming.The following is an example of the identity function.

function doSomething<T>(arg: T): T {
    return arg;
}

Modules and namespaces

TypeScript distinguishes between modules and namespaces. Both features in TypeScript support encapsulation of classes, interfaces, functions and variables into containers.


Thank you.
Happy Hacking!




No comments:

Post a Comment

Feel free to ask me for any query regarding my post

4 Pillars of OOPS

Inheritance- Inheritance is a mechanism in which one class acquires the property of another class. In OOP that is exactly what we are able t...