TYPESCRIPT
Dr.K.R.Prasanna Kumar AP(Sr.G)/IT
Contents to be covered
Typescript Introduction
Typescript instead of Express JS
What is TypeScript?�
Why should I use TypeScript?�
Features of Type Script
More about Type Script
Frameworks using Typescript
Installation steps
Installation steps
npm install –g typescript
tsc -v
Installation of visual studio code
https://code.visualstudio.com/download
Check the installed version of TypeScript
Typescript Basics
TypeScript and ECMAScript�
Typescript and Javascript relationship
TypeScript History
Components of TypeScript
The "Language Service" exposes an
additional layer around the core
compiler pipeline that are editor-
like applications.
Sample Program Execution
1.simplehello.ts
Compile the code tsc 1.simplehello.ts
After compilation 1.simplehello.js file can be generated
tsc program_name.ts
Sample Program Execution
1.simplehello.js
Run the js code node 1.simplehello.js
Sample program Addition
Sample program- Static type checking
TypeScript - Type Annotations
VARIABLE
Scope
Declaring Variables
Var Keyword
Local Type Variables
Variable declaration :var keyword examples
function scope. This variable has global scope in the function.
Variable declaration :let keyword examples
block-scope :This means that the scope of let variables is limited to their containing block, e.g. function, if else block or loop block
Var vs Let keyword
Advantages of using let over var
variables cannot be re-declared
Const keyword
Const variabes
DATA TYPES
unknown
const strVariable: unknown = "This is Test Value";
(strVariable as string).toLowerCase();
(OR)
const strVariable: unknown = "This is Test Value";
if (strVariable && typeof strVariable === 'string')
{
strVariable.toLowerCase();
}
undefined & null
DATA TYPES
Operators
Test ? expr1 : expr2
var num:number = -2
var result = num > 0 ?"positive":"non-positive"
console.log(result)
var num = 12
console.log(typeof num);
: ENUM
: ENUM
enums allow us to declare a set of named constants
i.e. a collection of related values that can be numeric or string values.
: ENUM
enums allow us to declare a set of named constants
i.e. a collection of related values that can be numeric or string values.
: ENUM Examples
enums allow us to declare a set of named constants i.e. a collection of related values that can be numeric or string values.
: ARRAY Examples
: ARRAY Examples
: ARRAY Examples
: ARRAY Functions
: ARRAY functions
: ARRAY function Examples
OUTPUT
:TUPLES
ACCESSING TUPLES
Creation of Tuples
:TUPLES examples
Tuples & Arrays
Tuples & Arrays
Functions
Functions in typescript Vs javascript
Syntax Function with parameters
Functions in typescript -examples
Output:
Functions in typescript -examples
Output:
Hello World
Optional Parameters
Default Parameters
Rest Parameters
Overloading functions
In typescript:
Function overloading- not possible like this
ERROR
Anonymous Function
var varName = function( [arguments] ) {
// function body
}
Class
Class example
Class Syntax
Class and instantiation Examples
Interface examples
Extending Interfaces
Modules
Modules
Method 1�module.ts
Module_im.ts
Output
Method 2�module.ts
Module_im.ts
Output
Method 3�module.ts
Module_im.ts
Output
Method 4�module2class.ts
Method 4�module_im2class.ts
Decorators
Decorators
Decorators
Decorators
Class Decorator - Example
Class Decorator - Example
Thank You