what is typescript typescript javascript typescript
play

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


  1. What is TypeScript?

  2. TypeScript = JavaScript

  3. TypeScript = Modern JavaScript

  4. TypeScript = Modern JavaScript + Types

  5. 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

  6. ArrayList<Dog> dogs = new ArrayList<Dog>();

  7. function cost(items) { let total = 0; for (let item of items) { total += item.price; } return total; }

  8. function cost(items) { let total = 0; any for (let item of items) { total += item.price; } return total; }

  9. function cost(items: any) { let total = 0; for (let item of items) { total += item.price; } return total; }

  10. declare let foo: any; // All of these are allowed! foo.bar; foo.baz; foo += foo; foo *= foo / foo; foo(); new foo();

  11. function cost(items: any) { let total = 0; for (let item of items) { total += item.price; } return total; }

  12. function cost(items: any) { let total = 0; number for (let item of items) { total += item.price; } return total; }

  13. function cost(items: any): number { let total: number = 0; for (let item of items) { total += item.price; } return total; }

  14. let n: number = 0; let s: string = ""; let b: boolean = false;

  15. function originDistance(point) { return Math.sqrt(point.x ** 2 + point.y ** 2); }

  16. function originDistance(point) { return Math.sqrt(point.x ** 2 + point.y ** 2); }

  17. function originDistance(point) { return Math.sqrt(point.x ** 2 + point.y ** 2); } originDistance({ x: 100, y: 100 }); class Coordinate { x = 0; y = 0; } originDistance(new Coordinate());

  18. interface HasXY { x: number; y: number; } function originDistance(point: HasXY) { return Math.sqrt(point.x ** 2 + y ** 2); } class Coordinate { x = 0; y = 0; } originDistance(new Coordinate());

  19. interface HasXY { x: number; y: number; } function originDistance(point: HasXY) { return Math.sqrt(point.x ** 2 + y ** 2); } class Coordinate { x = 0; y = 0; } originDistance({ x: 0, y: 0 });

  20. class CoordinateC { interface CoordinateI { x = 0; y = 0; x: number; y: number; } } let p: CoordinateC; let p: CoordinateI; let p: { x: number, y: number }

  21. 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; }

  22. 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; }

  23. 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; }

  24. 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; }

  25. /** * @param component A component * @param value Must be either "left", "right" or "center" */ function align(component: any, value: string) { // ... }

  26. /** * @param component A component * @param value Must be either "left", "right" or "center" */ function align(component: any, value: "left" | "right" | "center") { // ... }

  27. /** * @param component A component * @param value Must be either "left", "right" or "center" */ function align(component: any, value: "left" | "right" | "center") { // ... } align(Foo, "centre");

  28. string boolean number

  29. string boolean number

  30. string boolean number

  31. string boolean number null undefined

  32. number undefined

  33. number number | undefined undefined

  34. let foo = { bar: 0 }; foo.bar = 100; foo["bar"] = 100;

  35. function get(obj, propName) { // do some stuff... return obj[propName]; } function set(obj, propName, value) { // do some stuff... obj[propName] = value; } get(someObj, "some-property"); set(someObj, "other-property", 100);

  36. { x: T, y: U } T | U T & U keyof T T[K] { [P in K]: X } T extends U ? X : Y

  37. http://typescriptlang.org

Recommend


More recommend