2. Introduction
● TypeScript is an open-source, object-oriented programing language, which is developed
in October 2012 and maintained by Microsoft under the Apache 2 license.
● It is a strongly typed superset of JavaScript. It supports Object Oriented concept.
● TypeScript is not directly run on the browser. It needs a compiler to compile and generate
in JavaScript file.
● TypeScript is the ES6 version of JavaScript with some additional features.
● TypeScript uses TSC (TypeScript Compiler) compiler, which convert Typescript code (.ts
file) to JavaScript (.js file).
3. What is Echmascript
● ECMAScript is the scripting language standardized by Ecma International in the ECMA-
262 specification. ECMAScript is a language specification.
● Many languages follow and implement the ECMAScript specification, e.g., JavaScript,
ActionScript, JScript.
● Languages such as ActionScript, JavaScript, JScript all use ECMAScript as its core. As a
comparison, AS/JS/JScript are 3 different cars, but they all use the same engine... each of
their exteriors is different though, and there have been several modifications done to
each to make it unique.
5. Typescript versions
● The first version of TypeScript was released to the public in the month of 1st
October 2012 and was labeled as version 0.8.
● Typescript 1.0 in 2014
● Typescript 2.0 in September 2016
● Typescript 3.0 in July 2018
● Typescript 4.0 in August 2020
● The latest version of Typescript is TypeScript 4.6, released in February, 2022.
6. Installation
1. Install Editor
○ Visual Studio Code
○ Link : https://code.visualstudio.com/download#
2. Install Node.js Package Manager (npm)
○ provides a rich library of various JavaScript modules which simplifies the development of
web applications using Node.js
○ To install Node.js, go to the following link: https://nodejs.org/en/
○ Check version using command node –v
3. Install TypeScript
○ npm install typescript -g
○ Check the version using command tsc -v
7. Why use Typescript
● It supports Static typing, Strongly type, Modules, Optional Parameters, etc.
● It supports object-oriented programming features such as classes, interfaces,
inheritance, generics, etc.
● Object-oriented programming helps in making the codebase robust and clean
● The OOP features also makes TypeScript code more maintainable and organized.
● It is fast, simple, and most importantly, easy to learn.
● It provides the error-checking feature at compilation time. It will compile the code, and if
any error found, then it highlighted the mistakes before the script is run.
● It supports all JavaScript libraries because it is the superset of JavaScript.
8. Why use Typescript
● TypeScript support reusability because of the inheritance.
● It gives all the benefits of ES6 plus more productivity.
● TypeScript is a primary language for Angular application development.
● React is based on Javascript, but TypeScript can be helpful to React developers. It can be
used in React with some configuration settings
● Typescript also supports JSX
9. Static typing
● Static typing is when the compiler enforces that values use the same type.
● Above codes gives compiler error in typescript as data type number will be assigned to
salary statically so any incompatible value can not be assigned
● Data types
● To remove certain glitches and semantic error which occur in Javascript, Typescript
strongly supports static typing
● Benefits : Why Static Typing & Why is TypeScript so popular? | Engineering Education
(EngEd) Program | Section
10. Error Checking at Compile Time
● Javascript gets direct interpreted, so if any errors in code then they get displayed at
runtime, one at a time.
● Typescript is compiled language so, any syntactical mistakes in code will be know prior at
compile time itself to developer. And compiler to give set of errors at a time.
JS FILE TS FILE
11. Optional Parameters
● In TypeScript, the compiler checks every function call and issues an error in the following
cases:
○ The number of arguments is different from the number of parameters specified in the
function.
○ Or the types of arguments are not compatible with the types of function parameters.
● In typescript the compiler thoroughly checks the passing arguments, you need to
annotate optional parameters to instruct the compiler not to issue an error when you
omit the arguments.
● ‘?’ is used after argument to represent it as an optional parameter.
12. Optional Parameters
● In following code c is optional parameter
● The optional parameters must appear after the required parameters in the parameter
list.
13. Typescript classes
● For Javascript ES6 allowed to
define a class which is simply
syntactic sugar for creating
constructor function and
prototypal inheritance but we can
not annotate variables and
functions
● In typescript, class is simple and
easy to implement
● the object of this class is created
using new keyword
let person=new Person(2334, ‘Hari’,
‘Poojari’)
14. Typescript Inheritance
● One class can inherit visible properties of another class.
● The class which inherits properties and methods is called the child class.
And the class whose properties and methods are inherited is known as
the parent class.
● Code reusability
● Child classes can have their own additional variables and functions, thus
extending.