SlideShare une entreprise Scribd logo
1  sur  27
TypeScript
TypeScript Demo
• Basic Types
• Any Type
• Interfaces
• Classes
• Modules
• Generics
• Mixins
var n: number;
var a; // no type -> Any
var s = "Max"; // Contextual typing -> string
n = 5; // valid because 5 is a number
a = 5; // valid because a is of type Any
a = "Hello"; // valid because a is of type Any
n = "Hello"; // compile time error because
// "Hello" is not a number
Type Basics
Any
Primitive Types
Number
Boolean
String
Contextual typing
Determine result type
from expressions
automatically
var person = function (age: number) {
this.age = age;
this.growOld = function () {
this.age++;
alert(this.age);
}
this.growOldL = () => {
this.age++;
alert(this.age);
}
}
var p = new person(1);
setTimeout(p.growOldL, 100);
setTimeout(alert(p.age), 100);
Type Basics
Lambda Function
aka. Arrow function
• Eliminates the needs
for typing function
over and over again.
• Lexically captures
the meaning of this
function getAverage(a: number, b: number, c?: number) {
var total = a + b;
if (c)
total = total + c;
return total;
}
function getAverages(...a: number[]):number {
var total = 0;
for (var i = 0; i < a.length; i++) {
total += a[i];
}
return total;
}
Type Basics
Functions
Optional Parameters
Default Parameters
Rest Parameters
Rest parameters allow
caller to specify zero or
more arguments of the
specified type.
function getTotal(a: string, b: string, c: string): number;
function getTotal(a: number, b: number, c: number): number;
function getTotal(a: number, b: string, c: number): number;
// implementation signature
function getTotal(a: any, b: any, c?: any): number {
var total = parseInt(a, 10) + parseInt(b, 10) + parseInt(c,
10);
return total;
}
var result = getTotal(2, 2, 2);
alert(result);
Type Basics
Functions
• Overloading
interface IStudent {
id: number;
name: string;
onLeave?: boolean;
}
function printStudent(s: IStudent) {
}
// Describing function types
interface searchFunction {
(source: string, subString: string):boolean
}
var searchFunctionImpl: searchFunction = function (s, ss)
{
return true;
}
Type Basics
Interfaces
Interface can be used as
an abstract
type that can be
implemented by
concrete classes, but
they can also be used to
define any structure in
your TypeScript
program.
Interfaces are also
capable of describing
function types.
abstract class A {
foo(): number { return this.bar(); }
abstract bar(): number;
}
// error, Cannot create an instance of the abstract class 'A'
var a = new A();
class B extends A {
bar() { return 1; }
}
var b = new b(); // success, all abstracts are defined
Type Basics
Abstract Classes (v 1.6,
Sept 16th)
Similar in some ways to
interfaces, abstract
classes give you a way
of creating a base class,
complete with default
implementations
class Student {
private name: string;
constructor(name: string, age: number) {
this.name = name;
}
print() {
alert(this.name);
}
}
TODO: Static Types
Type Basics
Classes
TypeScript classes
become JavaScript
pseudo-classes
http://javascript.info/tutorial/pseudo-classical-pattern
Enforcement of private
variables is at runtime
only.
class Animal {
Name: string;
constructor(name: string) {
this.Name = name;
}
move(meters = 0) {
alert(this.Name + " moved " + meters);
}
}
class Snake extends Animal {
}
class MyStudent implements IStudent {
id: number;
name: string;
onLeave: boolean;
}
Type Basics
Types of Class
Heritage
Implements & Extends
There are two types of
class heritage in
TypeScript. A class can
implement an interface
using the implements
keyword
and a class can inherit
from another class using
the extends keyword.
// Internal Modules.
module Shipping {
export interface Ship {
name: string;
tons: number;
}
export class NewShip implements Ship {
name = "New Ship";
tons = 500;
}
}
// Splitting into multiple files.
/// <reference path=“Shipping.ts" />
tsc --out all.js app1.ts
Type Basics
Modules
Gives you various ways
to organize your code in
TypeScript.
1. Internal Modules
2. External Modules
// External Modules.
export class Ship {
name = "New Ship";
tons = 500;
}
// ---------------------------------
import Shipping = require('Ship')
var s = new Shipping.Ship();
// ---------------------------------
tsc --module commonjs app1.ts
tsc --module amd app1.ts
Type Basics
Modules
External Modules
• AMD using RequireJs
• CommonJs
class MyContainer<T> {
private array: T[];
constructor(array: T[]) {
this.array = array;
}
add(item: T) {
this.array.push(item);
}
}
var strContainer = new MyContainer<number>([1]);
strContainer.add(2);
Type Basics
Generics
Gives you the ablility to
create a component that
can work over a variety
of types rather than a
single one.
Generic Constraints
$('#id').html('TypeScript complains that $ is undefined');
Type Basics
Ambient Declarations
Ambient declarations
can be used to add type
information to existing
JavaScript. Commonly,
this would mean
adding type information
for your own existing
code, or for a third-
party library that you
want to consume in
your TypeScript
program.
http://definitelytyped.org/
• http://definitelytyped.org/tsd/
Other Stuff
• Mixins
• Iterators
• Decorators
• Union Types, Type Guards
• Intersection types
• Local type declarations
• ES6 generators
• Asyn/await
AngularJS 1.x + TypeScript
Aurangzaib Siddiqui
End of Part 1

Contenu connexe

Tendances

TypeScript: coding JavaScript without the pain
TypeScript: coding JavaScript without the painTypeScript: coding JavaScript without the pain
TypeScript: coding JavaScript without the painSander Mak (@Sander_Mak)
 
A Deeper look into Javascript Basics
A Deeper look into Javascript BasicsA Deeper look into Javascript Basics
A Deeper look into Javascript BasicsMindfire Solutions
 
Typescript 101 introduction
Typescript 101   introductionTypescript 101   introduction
Typescript 101 introductionBob German
 
Getting started with typescript and angular 2
Getting started with typescript  and angular 2Getting started with typescript  and angular 2
Getting started with typescript and angular 2Knoldus Inc.
 
Introduction to Javascript
Introduction to JavascriptIntroduction to Javascript
Introduction to JavascriptAmit Tyagi
 
TypeScript for Java Developers
TypeScript for Java DevelopersTypeScript for Java Developers
TypeScript for Java DevelopersYakov Fain
 
JavaScript Programming
JavaScript ProgrammingJavaScript Programming
JavaScript ProgrammingSehwan Noh
 
TypeScript Modules
TypeScript ModulesTypeScript Modules
TypeScript ModulesNoam Kfir
 
Javascript basics for automation testing
Javascript  basics for automation testingJavascript  basics for automation testing
Javascript basics for automation testingVikas Thange
 
JavaScript - An Introduction
JavaScript - An IntroductionJavaScript - An Introduction
JavaScript - An IntroductionManvendra Singh
 
Introduction about type script
Introduction about type scriptIntroduction about type script
Introduction about type scriptBinh Quan Duc
 
Type script, for dummies
Type script, for dummiesType script, for dummies
Type script, for dummiessantiagoaguiar
 

Tendances (20)

TypeScript: coding JavaScript without the pain
TypeScript: coding JavaScript without the painTypeScript: coding JavaScript without the pain
TypeScript: coding JavaScript without the pain
 
Getting started with typescript
Getting started with typescriptGetting started with typescript
Getting started with typescript
 
Typescript
TypescriptTypescript
Typescript
 
TypeScript 2 in action
TypeScript 2 in actionTypeScript 2 in action
TypeScript 2 in action
 
A Deeper look into Javascript Basics
A Deeper look into Javascript BasicsA Deeper look into Javascript Basics
A Deeper look into Javascript Basics
 
JavaScript Basics
JavaScript BasicsJavaScript Basics
JavaScript Basics
 
Typescript 101 introduction
Typescript 101   introductionTypescript 101   introduction
Typescript 101 introduction
 
Getting started with typescript and angular 2
Getting started with typescript  and angular 2Getting started with typescript  and angular 2
Getting started with typescript and angular 2
 
Introduction to Javascript
Introduction to JavascriptIntroduction to Javascript
Introduction to Javascript
 
Basics of JavaScript
Basics of JavaScriptBasics of JavaScript
Basics of JavaScript
 
TypeScript for Java Developers
TypeScript for Java DevelopersTypeScript for Java Developers
TypeScript for Java Developers
 
JavaScript Programming
JavaScript ProgrammingJavaScript Programming
JavaScript Programming
 
Javascript
JavascriptJavascript
Javascript
 
Google Dart
Google DartGoogle Dart
Google Dart
 
TypeScript Modules
TypeScript ModulesTypeScript Modules
TypeScript Modules
 
Javascript basics for automation testing
Javascript  basics for automation testingJavascript  basics for automation testing
Javascript basics for automation testing
 
JavaScript - An Introduction
JavaScript - An IntroductionJavaScript - An Introduction
JavaScript - An Introduction
 
Introduction to JavaScript Basics.
Introduction to JavaScript Basics.Introduction to JavaScript Basics.
Introduction to JavaScript Basics.
 
Introduction about type script
Introduction about type scriptIntroduction about type script
Introduction about type script
 
Type script, for dummies
Type script, for dummiesType script, for dummies
Type script, for dummies
 

En vedette

The Hitchhiker’s Guide to StackOverflow
The Hitchhiker’s Guide to StackOverflowThe Hitchhiker’s Guide to StackOverflow
The Hitchhiker’s Guide to StackOverflowSafeDK
 
Building RESTful APIs w/ Grape
Building RESTful APIs w/ GrapeBuilding RESTful APIs w/ Grape
Building RESTful APIs w/ GrapeDaniel Doubrovkine
 
StackOverflow Architectural Overview
StackOverflow Architectural OverviewStackOverflow Architectural Overview
StackOverflow Architectural OverviewFolio3 Software
 
Best Practices in SIS Documentation
Best Practices in SIS DocumentationBest Practices in SIS Documentation
Best Practices in SIS DocumentationEmerson Exchange
 

En vedette (7)

The Hitchhiker’s Guide to StackOverflow
The Hitchhiker’s Guide to StackOverflowThe Hitchhiker’s Guide to StackOverflow
The Hitchhiker’s Guide to StackOverflow
 
Oose kk
Oose kkOose kk
Oose kk
 
Unirac PV Racking Basics
Unirac PV Racking BasicsUnirac PV Racking Basics
Unirac PV Racking Basics
 
Building RESTful APIs w/ Grape
Building RESTful APIs w/ GrapeBuilding RESTful APIs w/ Grape
Building RESTful APIs w/ Grape
 
StackOverflow Architectural Overview
StackOverflow Architectural OverviewStackOverflow Architectural Overview
StackOverflow Architectural Overview
 
Best Practices in SIS Documentation
Best Practices in SIS DocumentationBest Practices in SIS Documentation
Best Practices in SIS Documentation
 
Cat SIS Fall 2011
Cat SIS Fall 2011Cat SIS Fall 2011
Cat SIS Fall 2011
 

Similaire à All You Need to Know About Type Script

Large Scale JavaScript with TypeScript
Large Scale JavaScript with TypeScriptLarge Scale JavaScript with TypeScript
Large Scale JavaScript with TypeScriptOliver Zeigermann
 
TypeScript Presentation - Jason Haffey
TypeScript Presentation - Jason HaffeyTypeScript Presentation - Jason Haffey
TypeScript Presentation - Jason HaffeyRalph Johnson
 
Typescript language extension of java script
Typescript language extension of java scriptTypescript language extension of java script
Typescript language extension of java scriptmichaelaaron25322
 
Static types on javascript?! Type checking approaches to ensure healthy appli...
Static types on javascript?! Type checking approaches to ensure healthy appli...Static types on javascript?! Type checking approaches to ensure healthy appli...
Static types on javascript?! Type checking approaches to ensure healthy appli...Arthur Puthin
 
Back to the Future with TypeScript
Back to the Future with TypeScriptBack to the Future with TypeScript
Back to the Future with TypeScriptAleš Najmann
 
Esoft Metro Campus - Certificate in c / c++ programming
Esoft Metro Campus - Certificate in c / c++ programmingEsoft Metro Campus - Certificate in c / c++ programming
Esoft Metro Campus - Certificate in c / c++ programmingRasan Samarasinghe
 
Functions And Header Files In C++ | Bjarne stroustrup
Functions And Header Files In C++ | Bjarne stroustrupFunctions And Header Files In C++ | Bjarne stroustrup
Functions And Header Files In C++ | Bjarne stroustrupSyedHaroonShah4
 
Data structures and algorithms lab1
Data structures and algorithms lab1Data structures and algorithms lab1
Data structures and algorithms lab1Bianca Teşilă
 
C programming(part 3)
C programming(part 3)C programming(part 3)
C programming(part 3)SURBHI SAROHA
 

Similaire à All You Need to Know About Type Script (20)

Synapseindia dot net development
Synapseindia dot net developmentSynapseindia dot net development
Synapseindia dot net development
 
Large Scale JavaScript with TypeScript
Large Scale JavaScript with TypeScriptLarge Scale JavaScript with TypeScript
Large Scale JavaScript with TypeScript
 
TypeScript Presentation - Jason Haffey
TypeScript Presentation - Jason HaffeyTypeScript Presentation - Jason Haffey
TypeScript Presentation - Jason Haffey
 
Typescript language extension of java script
Typescript language extension of java scriptTypescript language extension of java script
Typescript language extension of java script
 
Static types on javascript?! Type checking approaches to ensure healthy appli...
Static types on javascript?! Type checking approaches to ensure healthy appli...Static types on javascript?! Type checking approaches to ensure healthy appli...
Static types on javascript?! Type checking approaches to ensure healthy appli...
 
Back to the Future with TypeScript
Back to the Future with TypeScriptBack to the Future with TypeScript
Back to the Future with TypeScript
 
Csharp_mahesh
Csharp_maheshCsharp_mahesh
Csharp_mahesh
 
Swift, swiftly
Swift, swiftlySwift, swiftly
Swift, swiftly
 
Esoft Metro Campus - Certificate in c / c++ programming
Esoft Metro Campus - Certificate in c / c++ programmingEsoft Metro Campus - Certificate in c / c++ programming
Esoft Metro Campus - Certificate in c / c++ programming
 
Functions And Header Files In C++ | Bjarne stroustrup
Functions And Header Files In C++ | Bjarne stroustrupFunctions And Header Files In C++ | Bjarne stroustrup
Functions And Header Files In C++ | Bjarne stroustrup
 
OOC MODULE1.pptx
OOC MODULE1.pptxOOC MODULE1.pptx
OOC MODULE1.pptx
 
TechTalk - Dotnet
TechTalk - DotnetTechTalk - Dotnet
TechTalk - Dotnet
 
Notes(1).pptx
Notes(1).pptxNotes(1).pptx
Notes(1).pptx
 
88 c-programs
88 c-programs88 c-programs
88 c-programs
 
Ppt of c vs c#
Ppt of c vs c#Ppt of c vs c#
Ppt of c vs c#
 
Day 1
Day 1Day 1
Day 1
 
Data structures and algorithms lab1
Data structures and algorithms lab1Data structures and algorithms lab1
Data structures and algorithms lab1
 
C programming(part 3)
C programming(part 3)C programming(part 3)
C programming(part 3)
 
Functions struct&union
Functions struct&unionFunctions struct&union
Functions struct&union
 
Basics of objective c
Basics of objective cBasics of objective c
Basics of objective c
 

Plus de Folio3 Software

Shopify & Shopify Plus Ecommerce Development Experts
Shopify & Shopify Plus Ecommerce Development Experts Shopify & Shopify Plus Ecommerce Development Experts
Shopify & Shopify Plus Ecommerce Development Experts Folio3 Software
 
Magento and Magento 2 Ecommerce Development
Magento and Magento 2 Ecommerce Development Magento and Magento 2 Ecommerce Development
Magento and Magento 2 Ecommerce Development Folio3 Software
 
A Guideline to Test Your Own Code - Developer Testing
A Guideline to Test Your Own Code - Developer TestingA Guideline to Test Your Own Code - Developer Testing
A Guideline to Test Your Own Code - Developer TestingFolio3 Software
 
OWIN (Open Web Interface for .NET)
OWIN (Open Web Interface for .NET)OWIN (Open Web Interface for .NET)
OWIN (Open Web Interface for .NET)Folio3 Software
 
An Introduction to CSS Preprocessors (SASS & LESS)
An Introduction to CSS Preprocessors (SASS & LESS)An Introduction to CSS Preprocessors (SASS & LESS)
An Introduction to CSS Preprocessors (SASS & LESS)Folio3 Software
 
Introduction to SharePoint 2013
Introduction to SharePoint 2013Introduction to SharePoint 2013
Introduction to SharePoint 2013Folio3 Software
 
An Overview of Blackberry 10
An Overview of Blackberry 10An Overview of Blackberry 10
An Overview of Blackberry 10Folio3 Software
 
Enterprise Mobility - An Introduction
Enterprise Mobility - An IntroductionEnterprise Mobility - An Introduction
Enterprise Mobility - An IntroductionFolio3 Software
 
Distributed and Fault Tolerant Realtime Computation with Apache Storm, Apache...
Distributed and Fault Tolerant Realtime Computation with Apache Storm, Apache...Distributed and Fault Tolerant Realtime Computation with Apache Storm, Apache...
Distributed and Fault Tolerant Realtime Computation with Apache Storm, Apache...Folio3 Software
 
Introduction to Enterprise Service Bus
Introduction to Enterprise Service BusIntroduction to Enterprise Service Bus
Introduction to Enterprise Service BusFolio3 Software
 
NOSQL Database: Apache Cassandra
NOSQL Database: Apache CassandraNOSQL Database: Apache Cassandra
NOSQL Database: Apache CassandraFolio3 Software
 
Regular Expression in Action
Regular Expression in ActionRegular Expression in Action
Regular Expression in ActionFolio3 Software
 
HTTP Server Push Techniques
HTTP Server Push TechniquesHTTP Server Push Techniques
HTTP Server Push TechniquesFolio3 Software
 
Best Practices of Software Development
Best Practices of Software DevelopmentBest Practices of Software Development
Best Practices of Software DevelopmentFolio3 Software
 
Offline Data Access in Enterprise Mobility
Offline Data Access in Enterprise MobilityOffline Data Access in Enterprise Mobility
Offline Data Access in Enterprise MobilityFolio3 Software
 
Realtime and Synchronous Applications
Realtime and Synchronous ApplicationsRealtime and Synchronous Applications
Realtime and Synchronous ApplicationsFolio3 Software
 
Web Performance & Scalability Tools
Web Performance & Scalability ToolsWeb Performance & Scalability Tools
Web Performance & Scalability ToolsFolio3 Software
 

Plus de Folio3 Software (20)

Shopify & Shopify Plus Ecommerce Development Experts
Shopify & Shopify Plus Ecommerce Development Experts Shopify & Shopify Plus Ecommerce Development Experts
Shopify & Shopify Plus Ecommerce Development Experts
 
Magento and Magento 2 Ecommerce Development
Magento and Magento 2 Ecommerce Development Magento and Magento 2 Ecommerce Development
Magento and Magento 2 Ecommerce Development
 
Enter the Big Picture
Enter the Big PictureEnter the Big Picture
Enter the Big Picture
 
A Guideline to Test Your Own Code - Developer Testing
A Guideline to Test Your Own Code - Developer TestingA Guideline to Test Your Own Code - Developer Testing
A Guideline to Test Your Own Code - Developer Testing
 
OWIN (Open Web Interface for .NET)
OWIN (Open Web Interface for .NET)OWIN (Open Web Interface for .NET)
OWIN (Open Web Interface for .NET)
 
Introduction to Go-Lang
Introduction to Go-LangIntroduction to Go-Lang
Introduction to Go-Lang
 
An Introduction to CSS Preprocessors (SASS & LESS)
An Introduction to CSS Preprocessors (SASS & LESS)An Introduction to CSS Preprocessors (SASS & LESS)
An Introduction to CSS Preprocessors (SASS & LESS)
 
Introduction to SharePoint 2013
Introduction to SharePoint 2013Introduction to SharePoint 2013
Introduction to SharePoint 2013
 
An Overview of Blackberry 10
An Overview of Blackberry 10An Overview of Blackberry 10
An Overview of Blackberry 10
 
Enterprise Mobility - An Introduction
Enterprise Mobility - An IntroductionEnterprise Mobility - An Introduction
Enterprise Mobility - An Introduction
 
Distributed and Fault Tolerant Realtime Computation with Apache Storm, Apache...
Distributed and Fault Tolerant Realtime Computation with Apache Storm, Apache...Distributed and Fault Tolerant Realtime Computation with Apache Storm, Apache...
Distributed and Fault Tolerant Realtime Computation with Apache Storm, Apache...
 
Introduction to Docker
Introduction to DockerIntroduction to Docker
Introduction to Docker
 
Introduction to Enterprise Service Bus
Introduction to Enterprise Service BusIntroduction to Enterprise Service Bus
Introduction to Enterprise Service Bus
 
NOSQL Database: Apache Cassandra
NOSQL Database: Apache CassandraNOSQL Database: Apache Cassandra
NOSQL Database: Apache Cassandra
 
Regular Expression in Action
Regular Expression in ActionRegular Expression in Action
Regular Expression in Action
 
HTTP Server Push Techniques
HTTP Server Push TechniquesHTTP Server Push Techniques
HTTP Server Push Techniques
 
Best Practices of Software Development
Best Practices of Software DevelopmentBest Practices of Software Development
Best Practices of Software Development
 
Offline Data Access in Enterprise Mobility
Offline Data Access in Enterprise MobilityOffline Data Access in Enterprise Mobility
Offline Data Access in Enterprise Mobility
 
Realtime and Synchronous Applications
Realtime and Synchronous ApplicationsRealtime and Synchronous Applications
Realtime and Synchronous Applications
 
Web Performance & Scalability Tools
Web Performance & Scalability ToolsWeb Performance & Scalability Tools
Web Performance & Scalability Tools
 

Dernier

Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...Enterprise Knowledge
 
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Drew Madelung
 
Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024The Digital Insurer
 
AWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of TerraformAWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of TerraformAndrey Devyatkin
 
presentation ICT roal in 21st century education
presentation ICT roal in 21st century educationpresentation ICT roal in 21st century education
presentation ICT roal in 21st century educationjfdjdjcjdnsjd
 
Real Time Object Detection Using Open CV
Real Time Object Detection Using Open CVReal Time Object Detection Using Open CV
Real Time Object Detection Using Open CVKhem
 
GenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdfGenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdflior mazor
 
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...DianaGray10
 
Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...apidays
 
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdfUnderstanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdfUK Journal
 
Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)wesley chun
 
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot TakeoffStrategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoffsammart93
 
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationFrom Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationSafe Software
 
The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024Rafal Los
 
Histor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slideHistor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slidevu2urc
 
[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdfhans926745
 
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, AdobeApidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobeapidays
 
Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024The Digital Insurer
 
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc
 

Dernier (20)

Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...
 
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
 
Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024
 
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
 
AWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of TerraformAWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of Terraform
 
presentation ICT roal in 21st century education
presentation ICT roal in 21st century educationpresentation ICT roal in 21st century education
presentation ICT roal in 21st century education
 
Real Time Object Detection Using Open CV
Real Time Object Detection Using Open CVReal Time Object Detection Using Open CV
Real Time Object Detection Using Open CV
 
GenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdfGenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdf
 
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
 
Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...
 
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdfUnderstanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
 
Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)
 
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot TakeoffStrategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
 
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationFrom Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
 
The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024
 
Histor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slideHistor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slide
 
[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf
 
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, AdobeApidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
 
Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024
 
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
 

All You Need to Know About Type Script

  • 1.
  • 2.
  • 3.
  • 4.
  • 5.
  • 6.
  • 7.
  • 8.
  • 10. TypeScript Demo • Basic Types • Any Type • Interfaces • Classes • Modules • Generics • Mixins
  • 11. var n: number; var a; // no type -> Any var s = "Max"; // Contextual typing -> string n = 5; // valid because 5 is a number a = 5; // valid because a is of type Any a = "Hello"; // valid because a is of type Any n = "Hello"; // compile time error because // "Hello" is not a number Type Basics Any Primitive Types Number Boolean String Contextual typing Determine result type from expressions automatically
  • 12. var person = function (age: number) { this.age = age; this.growOld = function () { this.age++; alert(this.age); } this.growOldL = () => { this.age++; alert(this.age); } } var p = new person(1); setTimeout(p.growOldL, 100); setTimeout(alert(p.age), 100); Type Basics Lambda Function aka. Arrow function • Eliminates the needs for typing function over and over again. • Lexically captures the meaning of this
  • 13. function getAverage(a: number, b: number, c?: number) { var total = a + b; if (c) total = total + c; return total; } function getAverages(...a: number[]):number { var total = 0; for (var i = 0; i < a.length; i++) { total += a[i]; } return total; } Type Basics Functions Optional Parameters Default Parameters Rest Parameters Rest parameters allow caller to specify zero or more arguments of the specified type.
  • 14. function getTotal(a: string, b: string, c: string): number; function getTotal(a: number, b: number, c: number): number; function getTotal(a: number, b: string, c: number): number; // implementation signature function getTotal(a: any, b: any, c?: any): number { var total = parseInt(a, 10) + parseInt(b, 10) + parseInt(c, 10); return total; } var result = getTotal(2, 2, 2); alert(result); Type Basics Functions • Overloading
  • 15. interface IStudent { id: number; name: string; onLeave?: boolean; } function printStudent(s: IStudent) { } // Describing function types interface searchFunction { (source: string, subString: string):boolean } var searchFunctionImpl: searchFunction = function (s, ss) { return true; } Type Basics Interfaces Interface can be used as an abstract type that can be implemented by concrete classes, but they can also be used to define any structure in your TypeScript program. Interfaces are also capable of describing function types.
  • 16. abstract class A { foo(): number { return this.bar(); } abstract bar(): number; } // error, Cannot create an instance of the abstract class 'A' var a = new A(); class B extends A { bar() { return 1; } } var b = new b(); // success, all abstracts are defined Type Basics Abstract Classes (v 1.6, Sept 16th) Similar in some ways to interfaces, abstract classes give you a way of creating a base class, complete with default implementations
  • 17. class Student { private name: string; constructor(name: string, age: number) { this.name = name; } print() { alert(this.name); } } TODO: Static Types Type Basics Classes TypeScript classes become JavaScript pseudo-classes http://javascript.info/tutorial/pseudo-classical-pattern Enforcement of private variables is at runtime only.
  • 18. class Animal { Name: string; constructor(name: string) { this.Name = name; } move(meters = 0) { alert(this.Name + " moved " + meters); } } class Snake extends Animal { } class MyStudent implements IStudent { id: number; name: string; onLeave: boolean; } Type Basics Types of Class Heritage Implements & Extends There are two types of class heritage in TypeScript. A class can implement an interface using the implements keyword and a class can inherit from another class using the extends keyword.
  • 19. // Internal Modules. module Shipping { export interface Ship { name: string; tons: number; } export class NewShip implements Ship { name = "New Ship"; tons = 500; } } // Splitting into multiple files. /// <reference path=“Shipping.ts" /> tsc --out all.js app1.ts Type Basics Modules Gives you various ways to organize your code in TypeScript. 1. Internal Modules 2. External Modules
  • 20. // External Modules. export class Ship { name = "New Ship"; tons = 500; } // --------------------------------- import Shipping = require('Ship') var s = new Shipping.Ship(); // --------------------------------- tsc --module commonjs app1.ts tsc --module amd app1.ts Type Basics Modules External Modules • AMD using RequireJs • CommonJs
  • 21. class MyContainer<T> { private array: T[]; constructor(array: T[]) { this.array = array; } add(item: T) { this.array.push(item); } } var strContainer = new MyContainer<number>([1]); strContainer.add(2); Type Basics Generics Gives you the ablility to create a component that can work over a variety of types rather than a single one. Generic Constraints
  • 22. $('#id').html('TypeScript complains that $ is undefined'); Type Basics Ambient Declarations Ambient declarations can be used to add type information to existing JavaScript. Commonly, this would mean adding type information for your own existing code, or for a third- party library that you want to consume in your TypeScript program.
  • 24. Other Stuff • Mixins • Iterators • Decorators • Union Types, Type Guards • Intersection types • Local type declarations • ES6 generators • Asyn/await
  • 25.
  • 26.
  • 27. AngularJS 1.x + TypeScript Aurangzaib Siddiqui End of Part 1

Notes de l'éditeur

  1. Typescript is not a new language. It is at the core JS. It is JS with type annotations, decorators and generic etc. What it adds is type and powered by that is tooling. Tooling that is not possible with dynamic language like JavaScript. So when you compile it all goes away and what you get is simple javascript.
  2. ‘Contextual typing‘ is a form of type inference.
  3. ‘Contextual typing‘ is a form of type inference.
  4. ‘Contextual typing‘ is a form of type inference.
  5. In many languages, each overload has its own implementation but in TypeScript the overloads all decorate a single implementation
  6. ‘Contextual typing‘ is a form of type inference.
  7. ‘Contextual typing‘ is a form of type inference.
  8. ‘Contextual typing‘ is a form of type inference.
  9. ‘Contextual typing‘ is a form of type inference.
  10. interface Lengthwise { length: number; } function <T extends Lengthwise>(arg: T): T { console.log(arg.length); }
  11. All ambient declarations begin with the declare keyword. This tells the compiler that the following code block contains only type information and no implementation. Blocks of code created using the declare keyword will be erased during compilation and result in no JavaScript output. declare class jQuery { html(html: string): void; } declare function $(query: string): jQuery; /// <reference path="typings/jquery/jquery.d.ts" />
  12. https://github.com/ziaukhan/learn-typescript/blob/master/step16_union_types/app.ts http://blogs.msdn.com/b/typescript/archive/2014/11/18/what-s-new-in-the-typescript-type-system.aspx
  13. AtScript