Type Script Fundamentals.9273965
Type Script Fundamentals.9273965
TypeScript Fundamentals
https://www.ifourtechnolab.com/
Index
❏ Introduction
❏ What is TypeScript?
❏ Features of TypeScript
❏ Types
❏ Declaring Variables
❏ Arrow Functions
❏ Interfaces, Classes, Objects, Constructors
❏ Access Modifiers
❏ Properties
❏ Modules
https://www.ifourtechnolab.com/
❑Introduction
❏ TypeScript lets you write JavaScript the way you really want to.
❏ TypeScript is a typed superset of JavaScript that compiles to
plain JavaScript.
❏ TypeScript is pure object oriented with classes, interfaces and
statically typed like C# or Java.
❏ The popular JavaScript framework Angular 2.0 and Above are
written in TypeScript.
❏ Mastering TypeScript can help programmers to write object-
oriented programs and have them compiled to JavaScript, both
on server side and client side.
❏ You should have a good understanding of OOP concepts and
basic JavaScript
https://www.ifourtechnolab.com/
❑What is TypeScript?
https://www.ifourtechnolab.com/
❑Features of TypeScript
https://www.ifourtechnolab.com/
❑Types
❏ number : Double precision 64-bit floating point values. It can be used to represent both, integers and
fractions.
❏ string :Represents a sequence of Unicode characters
❏ boolean :Represents logical values, true and false
❏ void :Used on function return types to represent non-returning functions
❏ null :Represents an intentional absence of an object value.
❏ undefined :Denotes value given to all uninitialized variables
❏ User-defined types include
1. Enumerations (enums),
2. classes,
3. interfaces,
4. arrays, and
5. tuple.
https://www.ifourtechnolab.com/
❑Declaring Variables
https://www.ifourtechnolab.com/
❑Interfaces, Classes, Objects, Constructors
Syntax:
Syntax:
interface interface_name {
class class_name {
}
//class scope
}
Example:
Example:
interface Person {
class Car {
firstName: string,
engine: string; //field
lastName: string,
constructor(engine:string) { //constructor
sayHi: () => string
this.engine = engine
}
}
disp():void { //function
customer: Person = {
console.log("Engine is : "+ this.engine)
firstName:“iFour",
}
lastName:“TechnoLab",
}
sayHi: ():string =>{return "Hi there"}
var object_name = new class_name([ arguments ])
}
https://www.ifourtechnolab.com/
❑Arrow Functions
https://www.ifourtechnolab.com/
❑Access Modifiers
❏ A class can control the visibility of its data members to members of other classes.
❏ This capability is termed as Data Hiding or Encapsulation.
❏ Object Orientation uses the concept of access modifiers or access specifiers to implement the concept
of Encapsulation.
❏ The access specifiers/modifiers define the visibility of a class’s data members outside its defining class.
1. Public
2. Private
3. Protected
https://www.ifourtechnolab.com/
❑Modules
https://www.ifourtechnolab.com/
❑Modules Examples
JavaScript generated in both cases are same
Internal Module Syntax (Old)
var iFourModule ;
Syntax: (function (iFourModule) {
module iFourModule { function add(x, y) {
export function add(x, y) { console.log(x + y);
console.log(x+y); }
} iFourModule .add = add;
} })(iFourModule || (iFourModule = {}));
https://www.ifourtechnolab.com/
❑Ambient
❏ Ambient declarations are a way of telling the TypeScript compiler that the actual source code exists
elsewhere.
❏ When you are consuming a bunch of third party js libraries like jquery/angularjs/nodejs you can’t rewrite
it in TypeScript.
❏ Ensuring typesafety and intellisense while using these libraries will be challenging for a TypeScript
programmer.
❏ Ambient declarations help to seamlessly integrate other js libraries into TypeScript.
❏ Defining Ambients
Ambient declarations are by convention kept in a type declaration file with following extension (d.ts)
Example : iFour.d.ts
Syntax
declare module Module_Name {
}
https://www.ifourtechnolab.com/
Thank you
https://www.ifourtechnolab.com/