SlideShare a Scribd company logo
A developer friendly Javascript
Pradip Hudekar
pradip.hudekar@equalexperts.com
Javascript
● What is it?
● Who uses it?
● Why?
Problems
what haunts you during Javascript
development?
It is not typesafe
var a = 3
var b = 5
a++
c = a + b
a = "hello"
Can easily become complex
Ever tried writing Object Oriented Javascript?
var __extends = this.__extends || function (d, b) {
for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p];
function __() { this.constructor = d; }
__.prototype = b.prototype;
d.prototype = new __();
};
var Snake = (function (_super) {
__extends(Snake, _super);
function Snake() {
_super.call(this, "snake");
}
Snake.prototype.crawl = function () {
this.move();
console.log(this.name + ' is crawling');
};
return Snake;
})(Animal);
Hard to keep track of context
Context hell
var myObject = {
AddChildRowEvents: function(row, p2) {
if(document.attachEvent) {
row.attachEvent('onclick',function(){
this.DoSomething();});
} else {
row.addEventListener('click',function(){
this.DoSomething();}, false);
}},
DoSomething: function() { this.SomethingElse();} }
Long feedback cycle
● Errors come only at runtime
● And not even that in some cases
● Difficult to debug the minified js files
Can Typescript help us?
What’s in the menu
Typescript - what is it?
A language which compiles to clean Javascript
Virtually no learning curve
It is superset of Javascript
Static compilation
Catches errors early
Provides syntactic sugar
Reduces lots of boilerplate code
Readable code
Easy to understand and follow
Scalable
Offers classes, modules, and interfaces to help
you build robust components
Better tools
● Refactoring
● Intellisense
● Debugging support
● Code navigation
Say no to self = this
No more context related issue
Open Source
Community can make it even better
ECMA Script 6
Adopting many modern language features
Let’s dive in
Show me the real stuff
Basic Types
Boolean
var isDone: boolean = false;
Number
var height: number = 6;
String
var name: string = "bob";
Array
var list:number[] = [1, 2, 3];
var list:Array<number> = [1, 2, 3];
Basic Types Continued
Enum
enum Color {Red = 1, Green = 2, Blue = 4};var c: Color =
Color.Green;
var colorName: string = Color[2];
Any
var list:any[] = [1, true, "free"];
list[1] = 100;
Void
function warnUser(): void {
alert("This method does not return anything");
}
Interfaces
Interfaces are treated as contract
interface Shape {
color: string;
}
function DrawShape(shapeToDraw: Shape) {
alert(shapeToDraw.color);
}
Typescript uses Duck-Typing
function DrawShape(shapeToDraw: {color:string}) {
alert(shapeToDraw.color);
}
Interfaces continued
Interfaces can be also created for functions
interface ErrorCallback {
(message: string): boolean;
}
function GetData(url:string,error: ErrorCallback){
if(!tryGetData(url)){
error(‘Could not get data’);
}
}
GetData(‘http://foo.bar’,function(message:string){
alert(message);
});
Classes
class Greeter {
greeting: string;
constructor(message: string) {
this.greeting = message;
}
greet() {
return "Hello, " + this.greeting;
}
}
var greeter = new Greeter("world");
greeter.greet();
Implementing interfaces
interface Movable {
move();
}
class Animal implements Movable{
move() {
console.log(“Animal is moving”);
}
}
Inheritance
interface Movable { move(); }
interface Animal extends Movable {
eat(food: Eatable);
}
class Tiger extends Cat{
move() {
console.log(“Tiger is running ”);
}
eat() {
console.log(“Tiger is eating”);
}
}
Functions
Named function
function add(x: number, y: number): number {
return x+y;
}
Anonymous functionvar myAdd = function(x: number, y:
number): number {
return x+y;
};
Parameters
Optional parameter
function buildName(firstName: string, lastName?: string) {
if (lastName)
return firstName + " " + lastName;
else
return firstName;
}
Default parameterfunction buildName(firstName: string,
lastName = "Smith") {
return firstName + " " + lastName;
}
Generics
interface Lengthwise {
length: number;
}function loggingIdentity<T extends Lengthwise>(arg: T): T {
console.log(arg.length);
return arg;
}
Modules
Internal Modules
module Expertalks {
export class Session{
title: string;
speaker: string;
}
}
var session = new Expertalks.Session();
Modules Continued
External Modules
● CommonJS
● AMD
import shapes = require('Shapes');
I have existing js libraries
Very easy to migrate
Type Definition files (.d.ts)
declare class Bird{
public fly():void;
constructor();
}
Treasure of definitions @ DefinitelyTyped.org
References
TypeScript Language home
http://www.typescriptlang.org/
Interactive Playground
http://www.typescriptlang.org/Playground
Type definitions for popular JS libraries
http://www.definitelytyped.org/

More Related Content

PDF
Composition in JavaScript
Josh Mock
 
PDF
Farewell to #define private public
PVS-Studio
 
PDF
Groovify your java code by hervé roussel
Hervé Vũ Roussel
 
PDF
Java 8 Hipster slides
Oleg Prophet
 
PDF
The best of AltJava is Xtend
takezoe
 
PPTX
Fun with Lambdas: C++14 Style (part 2)
Sumant Tambe
 
PPTX
Type Driven Development with TypeScript
Garth Gilmour
 
PDF
Beginning Python
Agiliq Solutions
 
Composition in JavaScript
Josh Mock
 
Farewell to #define private public
PVS-Studio
 
Groovify your java code by hervé roussel
Hervé Vũ Roussel
 
Java 8 Hipster slides
Oleg Prophet
 
The best of AltJava is Xtend
takezoe
 
Fun with Lambdas: C++14 Style (part 2)
Sumant Tambe
 
Type Driven Development with TypeScript
Garth Gilmour
 
Beginning Python
Agiliq Solutions
 

What's hot (19)

PPTX
F# Presentation
mrkurt
 
PDF
Антихрупкий TypeScript | Odessa Frontend Meetup #17
OdessaFrontend
 
PPTX
Groovy Api Tutorial
guligala
 
PDF
MP in Clojure
Kent Ohashi
 
PPT
Functional techniques in Ruby
erockendude
 
PDF
Learning groovy -EU workshop
adam1davis
 
PDF
On Functional Programming - A Clojurian Perspective
looselytyped
 
PDF
Fantom - Programming Language for JVM, CLR, and Javascript
Kamil Toman
 
PDF
C++11 Idioms @ Silicon Valley Code Camp 2012
Sumant Tambe
 
PPTX
Ruby on rails tips
BinBin He
 
PPTX
Functional programming with Immutable .JS
Laura Steggles
 
PDF
Elm introduction
Mix & Go
 
PDF
Talk Code
Agiliq Solutions
 
PDF
Haskell for data science
John Cant
 
PDF
Fun with Lambdas: C++14 Style (part 1)
Sumant Tambe
 
ODP
Learning groovy 1: half day workshop
Adam Davis
 
PDF
"How was it to switch from beautiful Perl to horrible JavaScript", Viktor Tur...
Fwdays
 
PPTX
Print input-presentation
Martin McBride
 
PDF
"Немного о функциональном программирование в JavaScript" Алексей Коваленко
Fwdays
 
F# Presentation
mrkurt
 
Антихрупкий TypeScript | Odessa Frontend Meetup #17
OdessaFrontend
 
Groovy Api Tutorial
guligala
 
MP in Clojure
Kent Ohashi
 
Functional techniques in Ruby
erockendude
 
Learning groovy -EU workshop
adam1davis
 
On Functional Programming - A Clojurian Perspective
looselytyped
 
Fantom - Programming Language for JVM, CLR, and Javascript
Kamil Toman
 
C++11 Idioms @ Silicon Valley Code Camp 2012
Sumant Tambe
 
Ruby on rails tips
BinBin He
 
Functional programming with Immutable .JS
Laura Steggles
 
Elm introduction
Mix & Go
 
Talk Code
Agiliq Solutions
 
Haskell for data science
John Cant
 
Fun with Lambdas: C++14 Style (part 1)
Sumant Tambe
 
Learning groovy 1: half day workshop
Adam Davis
 
"How was it to switch from beautiful Perl to horrible JavaScript", Viktor Tur...
Fwdays
 
Print input-presentation
Martin McBride
 
"Немного о функциональном программирование в JavaScript" Алексей Коваленко
Fwdays
 
Ad

Similar to Typescript - A developer friendly javascript (20)

PDF
Back to the Future with TypeScript
Aleš Najmann
 
PPTX
Complete Notes on Angular 2 and TypeScript
EPAM Systems
 
PDF
TypeScript Introduction
Hans Höchtl
 
PPTX
TypeScript by Howard
LearningTech
 
PPTX
Howard type script
LearningTech
 
PDF
Introduction to TypeScript
André Pitombeira
 
PPTX
Type script by Howard
LearningTech
 
PPTX
Introduction to TypeScript
Tomas Corral Casas
 
PPTX
Type script
Zunair Shoes
 
PPTX
TypeScript - All you ever wanted to know - Tech Talk by Epic Labs
Alfonso Peletier
 
PDF
Introduction to typescript
Mario Alexandro Santini
 
PPTX
TypeScript
Udaiappa Ramachandran
 
PPTX
Typescript barcelona
Christoffer Noring
 
PPTX
TypeScript-SPS-melb.pptx
accordv12
 
PDF
A la découverte de TypeScript
Denis Voituron
 
PPTX
TypeScript . the JavaScript developer best friend!
Alessandro Giorgetti
 
PDF
Typescript is the best
GlobalLogic Ukraine
 
PDF
Typescript is the best by Maxim Kryuk
GlobalLogic Ukraine
 
PPT
Typescript - why it's awesome
Piotr Miazga
 
PPTX
TypeScript Overview
Aniruddha Chakrabarti
 
Back to the Future with TypeScript
Aleš Najmann
 
Complete Notes on Angular 2 and TypeScript
EPAM Systems
 
TypeScript Introduction
Hans Höchtl
 
TypeScript by Howard
LearningTech
 
Howard type script
LearningTech
 
Introduction to TypeScript
André Pitombeira
 
Type script by Howard
LearningTech
 
Introduction to TypeScript
Tomas Corral Casas
 
Type script
Zunair Shoes
 
TypeScript - All you ever wanted to know - Tech Talk by Epic Labs
Alfonso Peletier
 
Introduction to typescript
Mario Alexandro Santini
 
Typescript barcelona
Christoffer Noring
 
TypeScript-SPS-melb.pptx
accordv12
 
A la découverte de TypeScript
Denis Voituron
 
TypeScript . the JavaScript developer best friend!
Alessandro Giorgetti
 
Typescript is the best
GlobalLogic Ukraine
 
Typescript is the best by Maxim Kryuk
GlobalLogic Ukraine
 
Typescript - why it's awesome
Piotr Miazga
 
TypeScript Overview
Aniruddha Chakrabarti
 
Ad

Recently uploaded (20)

PPTX
Audio Editing and it's techniques in computer graphics.pptx
fosterbayirinia3
 
PDF
Community & News Update Q2 Meet Up 2025
VictoriaMetrics
 
PPTX
AIRLINE PRICE API | FLIGHT API COST |
philipnathen82
 
DOCX
The Future of Smart Factories Why Embedded Analytics Leads the Way
Varsha Nayak
 
PPTX
Odoo Integration Services by Candidroot Solutions
CandidRoot Solutions Private Limited
 
PDF
Micromaid: A simple Mermaid-like chart generator for Pharo
ESUG
 
PPTX
Save Business Costs with CRM Software for Insurance Agents
Insurance Tech Services
 
PPTX
AI-Ready Handoff: Auto-Summaries & Draft Emails from MQL to Slack in One Flow
bbedford2
 
PDF
Jenkins: An open-source automation server powering CI/CD Automation
SaikatBasu37
 
PPTX
Services offered by Dynamic Solutions in Pakistan
DaniyaalAdeemShibli1
 
PDF
Why Use Open Source Reporting Tools for Business Intelligence.pdf
Varsha Nayak
 
PDF
Microsoft Teams Essentials; The pricing and the versions_PDF.pdf
Q-Advise
 
PDF
How to Seamlessly Integrate Salesforce Data Cloud with Marketing Cloud.pdf
NSIQINFOTECH
 
PPTX
introduction to dart --- Section one .pptx
marknaiem92
 
PDF
QAware_Mario-Leander_Reimer_Architecting and Building a K8s-based AI Platform...
QAware GmbH
 
PPTX
Benefits of DCCM for Genesys Contact Center
pointel ivr
 
PDF
Bandai Playdia The Book - David Glotz
BluePanther6
 
PPTX
10 Hidden App Development Costs That Can Sink Your Startup.pptx
Lunar Web Solution
 
PDF
Comprehensive Salesforce Implementation Services.pdf
VALiNTRY360
 
PDF
Winning Business in a Slowing Economy, How CPQ helps Manufacturers Protect Ma...
systemscincom
 
Audio Editing and it's techniques in computer graphics.pptx
fosterbayirinia3
 
Community & News Update Q2 Meet Up 2025
VictoriaMetrics
 
AIRLINE PRICE API | FLIGHT API COST |
philipnathen82
 
The Future of Smart Factories Why Embedded Analytics Leads the Way
Varsha Nayak
 
Odoo Integration Services by Candidroot Solutions
CandidRoot Solutions Private Limited
 
Micromaid: A simple Mermaid-like chart generator for Pharo
ESUG
 
Save Business Costs with CRM Software for Insurance Agents
Insurance Tech Services
 
AI-Ready Handoff: Auto-Summaries & Draft Emails from MQL to Slack in One Flow
bbedford2
 
Jenkins: An open-source automation server powering CI/CD Automation
SaikatBasu37
 
Services offered by Dynamic Solutions in Pakistan
DaniyaalAdeemShibli1
 
Why Use Open Source Reporting Tools for Business Intelligence.pdf
Varsha Nayak
 
Microsoft Teams Essentials; The pricing and the versions_PDF.pdf
Q-Advise
 
How to Seamlessly Integrate Salesforce Data Cloud with Marketing Cloud.pdf
NSIQINFOTECH
 
introduction to dart --- Section one .pptx
marknaiem92
 
QAware_Mario-Leander_Reimer_Architecting and Building a K8s-based AI Platform...
QAware GmbH
 
Benefits of DCCM for Genesys Contact Center
pointel ivr
 
Bandai Playdia The Book - David Glotz
BluePanther6
 
10 Hidden App Development Costs That Can Sink Your Startup.pptx
Lunar Web Solution
 
Comprehensive Salesforce Implementation Services.pdf
VALiNTRY360
 
Winning Business in a Slowing Economy, How CPQ helps Manufacturers Protect Ma...
systemscincom
 

Typescript - A developer friendly javascript