2. • TypeScript este un limbaj de programare liber
și deschis, dezvoltat și întreținut de Microsoft.
Este o suprasetare strict sintactică a
JavaScript-ului și adaugă programarea optimă
statică și programarea orientată pe obiecte pe
bază de clase a limbajului.
3. Anders Hejlsberg
Arhitectul principal al lui
C# și creatorul lui Delphi
și al lui Turbo Pascal, a
lucrat la dezvoltarea
TypeScript.
TypeScript poate fi folosit
pentru a dezvolta
aplicații JavaScript
pentru execuția pe
partea clientului sau a
serverului (Node.js).
4. Features of TypeScript
ITVDN
• TypeScript is just JavaScript;
• TypeScript supports other JS libraries;
• JavaScript is TypeScript;
• TypeScript is portable.
5.
6.
7. Why Use TypeScript?
• Compilation
• Strong Static Typing
• TypeScript supports type definitions for
existing JavaScript libraries
• TypeScript supports Object Oriented
Programming
8. Components of TypeScript
• Language: It comprises of the syntax, keywords,
and type annotations.
• The TypeScript Compiler: The TypeScript
compiler (tsc) converts the instructions written in
TypeScript to its JavaScript equivalent.
• The TypeScript Language Service: The language
service supports the common set of a typical
editor operations like statement completions,
signature help, code formatting and outlining,
colorization, etc.
9.
10. TypeScript ─ Try it Option Online
http://www.typescriptlang.org/play/
27. Conditional Operator (?)
Test ? expr1 : expr2
• Test: refers to the conditional expression
• expr1:value returned if the condition is true
• expr2: value returned if the condition is false
var num:number=-2 ;
var result= num > 0 ?"positive":"non-positive"
console.log(result);
29. TypeScript ─ Decision Making
if(boolean_expression)
{
// statement(s) will execute
if the Boolean
expression is true
}
else
{
// statement(s) will execute
if the Boolean
expression is false
}
var num:number = 12;
if (num % 2==0)
{
console.log("Even");
}
else
{
console.log("Odd");
}
32. The while Loop
while(condition)
{
// statements if
the condition
is true
}
var num:number=5;
var factorial:number=1;
while(num >=1)
{
factorial=factorial * num;
num--;
}
console.log("The factorial is "+factorial);
33. The for Loop
for ( initial_count_value; termination-condition; step)
{
//statements
}
var num:number= 5;
var i:number;
var factorial=1;
for( i=num; i>=1; i--)
{ factorial*=i; }
console.log(factorial)
34. The for...in loop
for (var val in list)
{
//statements
}
var j:any;
var n:any=“abc"
for(j in n)
{
console.log(n[j])
}
35. The do…while loop
Do {
//statements
}wh
var n:number=10;
do
{
console.log(n);
n--;
}while(n>=0);
39. Anonymous Function
var msg= function()
{
return "hello world";
}
console.log(msg())
-----------------------------------------------------
var res=function(a:number,b:number)
{
return a*b;
};
console.log(res(12,2))
40. The Function Constructor
var res=new Function( [arguments] ) { ... }
-------------
var myFunction =
new Function("a", "b", "return a * b");
var x = myFunction(4, 3);
console.log(x);
41. Lambda Expression
It is an anonymous function expression that
points to a single line of code.
( [param1, parma2,…param n] )=>statement;
-----------------------------
var foo=(x:number)=>10+x
console.log(foo(100)) //outputs 110
46. TypeScript – Arrays
var alphas:string[];
alphas=["1","2","3","4"]
console.log(alphas[0]);
console.log(alphas[1]);
----------------
var names = new Array("Mary", "Tom", "Jack", "Jill");
for (var i = 0; i < names.length; i++) {
console.log(names[i]);
}
55. Classes
class Student {
fullName: string;
constructor(public firstName, public middleInitial, public lastName) {
this.fullName = firstName + " " + middleInitial + " " + lastName;
}
}
interface Person {
firstName: string;
lastName: string;
}
function greeter(person : Person) {
return "Hello, " + person.firstName + " " + person.lastName; }
var user = new Student("Jane", "M.", "User");
document.body.innerHTML = greeter(user);
56. public - по умолчанию
private - не может быть доступен вне этого
класса
protected - аналогично private за исключением
того, что члены, объявленные protected, могут
быть доступны в подклассах.
readonly
static - которые видны в классе без создания
экземпляра