2 + 3 = ${addResult}
14 |
2 + 3 = ${powResult}
15 | `; 16 | } 17 | -------------------------------------------------------------------------------- /Chapter10/readme.md: -------------------------------------------------------------------------------- 1 | # Chapter 10 2 | 3 | ``` 4 | cd cd chapters/chapter_10 5 | npm install 6 | ts-node 01_callback.ts 7 | ts-node 02_promisify.ts 8 | ts-node 03_file_system.ts 9 | ts-node 04_database.ts 10 | ts-node 05_http_hello.ts 11 | ts-node 06_express_hello.ts 12 | ts-node 07_express_routing.ts 13 | ts-node 08_express_middleware.ts 14 | ``` 15 | 16 | ``` 17 | ts-node 09_mvc/index.ts 18 | ``` 19 | 20 | ``` 21 | ts-node 10_inversify_express_utils/index.ts 22 | ``` 23 | -------------------------------------------------------------------------------- /Chapter01/02_variables.ts: -------------------------------------------------------------------------------- 1 | namespace type_inference_variables_demo { 2 | 3 | let testVar1; // variable is declared but not initialized 4 | console.log(testVar1); // shows undefined 5 | console.log(typeof testVar1); // shows undefined 6 | 7 | let testVar2 = null; // variable is declared and null is assigned as value 8 | console.log(testVar2); // shows null 9 | console.log(typeof testVar2); // shows object 10 | 11 | } 12 | -------------------------------------------------------------------------------- /Chapter02/20_index_signature.ts: -------------------------------------------------------------------------------- 1 | namespace index_signature_demo { 2 | 3 | let foo1: any = {}; 4 | foo1.hello = "World"; 5 | console.log(foo1.hello); // World 6 | 7 | let foo2: any = {}; 8 | foo2["hello"] = "World"; 9 | console.log(foo2["hello"]); // World 10 | 11 | interface StringArray { 12 | [index: number]: string; 13 | } 14 | 15 | let myArray: StringArray = ["Bob", "Fred"]; 16 | let myStr: string = myArray[0]; 17 | 18 | } 19 | -------------------------------------------------------------------------------- /Chapter03/02_function_types.ts: -------------------------------------------------------------------------------- 1 | namespace function_types_demo { 2 | 3 | function greetNamed(name?: string): string { 4 | return `Hi! ${name}`; 5 | } 6 | 7 | let greetUnnamed1: (name: string) => string; 8 | 9 | greetUnnamed1 = function(name: string): string { 10 | return `Hi! ${name}`; 11 | }; 12 | 13 | let greetUnnamed2: (name: string) => string = function(name: string): string { 14 | return `Hi! ${name}`; 15 | }; 16 | 17 | } 18 | -------------------------------------------------------------------------------- /Chapter04/15_interfaces.ts: -------------------------------------------------------------------------------- 1 | namespace interfaces_demo { 2 | 3 | interface Weapon { 4 | tryHit(fromDistance: number): boolean; 5 | } 6 | 7 | class Katana implements Weapon { 8 | public tryHit(fromDistance: number) { 9 | return fromDistance <= 2; 10 | } 11 | } 12 | 13 | class Shuriken implements Weapon { 14 | public tryHit(fromDistance: number) { 15 | return fromDistance <= 15; 16 | } 17 | } 18 | 19 | } 20 | -------------------------------------------------------------------------------- /Chapter12/web/frontend/components/loading.component.ts: -------------------------------------------------------------------------------- 1 | import { Component } from "@angular/core"; 2 | 3 | @Component({ 4 | selector: "app-loading", 5 | template: ` 6 |
27 | {props.description} 28 |
29 | 30 | {props.linkText} 31 | 32 |{`${this.props.name} must be numeric!`}
45 |