SLIDE 1
What is TypeScript? TypeScript = JavaScript TypeScript = Modern - - PowerPoint PPT Presentation
What is TypeScript? TypeScript = JavaScript TypeScript = Modern - - PowerPoint PPT Presentation
What is TypeScript? TypeScript = JavaScript TypeScript = Modern JavaScript TypeScript = Modern JavaScript + Types Open source and open development Closely track ECMAScript standard Innovate in type system Best of breed tooling Continuously
SLIDE 2
SLIDE 3
What is TypeScript?
SLIDE 4
SLIDE 5
TypeScript = JavaScript
SLIDE 6
TypeScript = Modern JavaScript
SLIDE 7
TypeScript = Modern JavaScript + Types
SLIDE 8
Open source and open development Closely track ECMAScript standard Innovate in type system Best of breed tooling Continuously lower barrier to entry Community, community, community
SLIDE 9
SLIDE 10
SLIDE 11
ArrayList<Dog> dogs = new ArrayList<Dog>();
SLIDE 12
SLIDE 13
SLIDE 14
function cost(items) { let total = 0; for (let item of items) { total += item.price; } return total; }
SLIDE 15
function cost(items) { let total = 0; for (let item of items) { total += item.price; } return total; }
any
SLIDE 16
function cost(items: any) { let total = 0; for (let item of items) { total += item.price; } return total; }
SLIDE 17
declare let foo: any; // All of these are allowed! foo.bar; foo.baz; foo += foo; foo *= foo / foo; foo(); new foo();
SLIDE 18
function cost(items: any) { let total = 0; for (let item of items) { total += item.price; } return total; }
SLIDE 19
function cost(items: any) { let total = 0; for (let item of items) { total += item.price; } return total; }
number
SLIDE 20
function cost(items: any): number { let total: number = 0; for (let item of items) { total += item.price; } return total; }
SLIDE 21
SLIDE 22
SLIDE 23
let n: number = 0; let s: string = ""; let b: boolean = false;
SLIDE 24
function originDistance(point) { return Math.sqrt(point.x ** 2 + point.y ** 2); }
SLIDE 25
function originDistance(point) { return Math.sqrt(point.x ** 2 + point.y ** 2); }
SLIDE 26
function originDistance(point) { return Math.sqrt(point.x ** 2 + point.y ** 2); }
- riginDistance({ x: 100, y: 100 });
class Coordinate { x = 0; y = 0; }
- riginDistance(new Coordinate());
SLIDE 27
interface HasXY { x: number; y: number; } function originDistance(point: HasXY) { return Math.sqrt(point.x ** 2 + y ** 2); } class Coordinate { x = 0; y = 0; }
- riginDistance(new Coordinate());
SLIDE 28
interface HasXY { x: number; y: number; } function originDistance(point: HasXY) { return Math.sqrt(point.x ** 2 + y ** 2); } class Coordinate { x = 0; y = 0; }
- riginDistance({ x: 0, y: 0 });
SLIDE 29
interface CoordinateI { x: number; y: number; } let p: CoordinateI; class CoordinateC { x = 0; y = 0; } let p: CoordinateC; let p: { x: number, y: number }
SLIDE 30
SLIDE 31
function padLeft(str: string, padding: any) { let padChar; let padCount; if (typeof padding === "number") { padChar = " "; padCount = padding; } else { padCount = padding.count; padChar = padding.char; } return Array(padCount + 1).join(padChar) + str; }
SLIDE 32
function padLeft(str: string, padding: any) { let padChar; let padCount; if (typeof padding === "number") { padChar = " "; padCount = padding; } else { padCount = padding.count; padChar = padding.char; } return Array(padCount + 1).join(padChar) + str; }
SLIDE 33
function padLeft(str: string, padding: any) { let padChar; let padCount; if (typeof padding === "number") { padChar = " "; padCount = padding; } else { padCount = padding.count; padChar = padding.char; } return Array(padCount + 1).join(padChar) + str; }
SLIDE 34
function padLeft(str: string, padding: number | Options) { let padChar; let padCount; if (typeof padding === "number") { padChar = " "; padCount = padding; } else { padCount = padding.count; padChar = padding.char; } return Array(padCount + 1).join(padChar) + str; }
SLIDE 35
SLIDE 36
/** * @param component A component * @param value Must be either "left", "right" or "center" */ function align(component: any, value: string) { // ... }
SLIDE 37
/** * @param component A component * @param value Must be either "left", "right" or "center" */ function align(component: any, value: "left" | "right" | "center") { // ... }
SLIDE 38
/** * @param component A component * @param value Must be either "left", "right" or "center" */ function align(component: any, value: "left" | "right" | "center") { // ... } align(Foo, "centre");
SLIDE 39
number string boolean
SLIDE 40
number string boolean
SLIDE 41
number string boolean
SLIDE 42
number string boolean undefined null
SLIDE 43
number undefined
SLIDE 44
number undefined number | undefined
SLIDE 45
SLIDE 46
let foo = { bar: 0 }; foo.bar = 100; foo["bar"] = 100;
SLIDE 47
function get(obj, propName) { // do some stuff... return obj[propName]; } function set(obj, propName, value) { // do some stuff...
- bj[propName] = value;
} get(someObj, "some-property"); set(someObj, "other-property", 100);
SLIDE 48
{ x: T, y: U } T | U T & U keyof T T[K] { [P in K]: X } T extends U ? X : Y
SLIDE 49
SLIDE 50
SLIDE 51
SLIDE 52
SLIDE 53