Professional Documents
Culture Documents
TypeScript Intro PDF
TypeScript Intro PDF
Rainer Stropek
software architects gmbh
TypeScript Mail
Web
Twitter
rainer@timecockpit.com
http://www.timecockpit.com
@rstropek
JavaScript on Steroids
Saves the day.
Why TypeScript?
JavaScript is great because of its reach
JavaScript is everywhere
Object Types
Classes, Modules, Interfaces, …
Typing Basics
Types are used during editing
and compiling
No type information in resulting
JavaScript code
Contextual Typing
Determine result type from
expressions automatically
Typing Basics
TypeScript classes become
JavaScript pseudo-classes
http://javascript.info/tutorial/pseudo-classical-pattern
Typing Basics
module CrmModule {
// Define an interface that specifies
Language Overview
// what a person must consist of. Modules
export interface IPerson {
firstName: string; Interfaces
lastName: string;
}
…
}
TypeScript Introduction
Language Overview
export class Person implements IPerson {
private isNew: bool;
public firstName: string;
Language Overview
module CrmModule {
…
// A static member...
static convertToUsd(amountInEur: number): number {
return amountInEur * 1.3;
}
}
}
}
TypeScript Introduction
import S = CrmModule.Sales;
var s: S.Opportunity;
s = new S.Opportunity();
s.potentialRevenueEur = 1000;
s.addContact(v);
s.addContact({ firstName: "Rainer", lastName: "Stropek" });
s.addContact(<CrmModule.IPerson> {
firstName: "Rainer", lastName: "Stropek" });
Interfaces
Interfaces are only used for
editing and compiling
No type information in resulting
JavaScript code
Structural Subtyping
interface JQueryStatic {
TypeScript Type
(element: Element): JQuery; Definition Library
(selector: string, context?: any): JQuery; See link in the resources section
}
public fullName() {
return this.lastName + ", " + this.firstName;
}
}
}
TypeScript Introduction
app.listen(8088);
TypeScript Introduction
Sample
http://bit.ly/TypeScriptSample
TypeScript Introduction
Rainer Stropek
software architects gmbh
Q&A
Mail rainer@timecockpit.com
Web http://www.timecockpit.com
Twitter @rstropek