W3schools | Tutorialspoint | JavaTpoint

Just another WordPress site

TypeScript tutorial

TypeScript:

TypeScript is a superset of JavaScript which primarily provides optional static typing, classes and interfaces. One of the big benefits is to enable IDEs to provide a richer environment for spotting common errors as you type the code.

TypeScript doesn’t run in the browser. The code written in typescript is compiled to JavaScript, which then runs in the browser.

TypeScript is open source. It was designed by Anders Hejlsberg (the lead architect of C#) at Microsoft.

Features of TypeScript:

  1. The code written in typescript is compiled to the JavaScript for the purpose of execution.
  2. As we already discussed that the code written in typescript is compiled to the JavaScript which can reuse all of the existing JavaScript frameworks, tools, and libraries.
  3. As TypeScript is a superset of JavaScript so any valid .js file can be renamed to .ts and compiled with other TypeScript files.
  4. TypeScript is portable i.e. it can run on any environment that JavaScript runs on.
  5. TypeScript provides optional static typing. JavaScript is dynamically typed. This means JavaScript does not know what type a variable is until it actsually instantiated at run-time. This also means that it may be too late. TypeScript adds type support to JavaScript. TypeScript makes typing a bit easier and a lot less explicit by the usage of type inference. For example: var msg = “hello” in TypeScript is the same as var msg : string = “hello”. TLS (TypeScript Language Service) provides the facility to identify the type of the variable based on its value if it is declared with no type.
  6. TypeScript supports Object Oriented Programming concepts like classes, object, interfaces and inheritance etc.
  7. TypeScript Definition file with .d.ts extension provides definition for external JavaScript libraries.
  8. TypeScript provides strict null checks. TypeScript compiler will not allow undefined to be assigned to a variable unless you explicitly declare it to be of nullable type. For example, let num1 : number = undefined will result in a compile error. This fits perfectly with type theory, since undefined is not a number. One can define x to be a sum type of number and undefined to correct this: let num1 : number | undefined = undefined.

TypeScript tutorial:

Content Protection by DMCA.com

 

Scroll to top