Slide 1

Slide 1 text

Angular(あるいはNestJS) ではじめるTypeScript Fukuoka JS #8

Slide 2

Slide 2 text

Noriyuki Shinpuku ng-fukuoka organizer @puku0x 2 VEGA corporation Co., Ltd.

Slide 3

Slide 3 text

3

Slide 4

Slide 4 text

TypeScript ● Superset of JavaScript ● Type safety ● Strong tools 4 TypeScript ES201x ES5

Slide 5

Slide 5 text

5 https://speakerdeck.com/pirosikick/the-state-of-javascript-in-fecf-2018-number-fec-fukuoka

Slide 6

Slide 6 text

6 https://2018.stateofjs.com/javascript-flavors/typescript/

Slide 7

Slide 7 text

7

Slide 8

Slide 8 text

8 Angular

Slide 9

Slide 9 text

Angular A platform for building modern Web Apps ● Move faster ● Scale better ● Reach further https://angular.io/ 9

Slide 10

Slide 10 text

10 Angular Protractor Forms PWA Augury Language Services Router Elements CDK Universal Karma Labs Compiler i18n Http Material Animations CLI Angular products

Slide 11

Slide 11 text

11

Slide 12

Slide 12 text

Type safety 12 function add(a: number, b: number) { return a + b; } add(1, 2); // 3 add(1, '2'); // Argument of type '"2"' is not assignable to parameter of type 'number'.

Slide 13

Slide 13 text

Interfaces 13 export interface Todo { id: number; text: string; enabled: boolean; } export interface OnInit { ngOnInit(): void; }

Slide 14

Slide 14 text

Example: Life cycle hooks 14 @Component({...}) export class AppComponent implements OnInit, OnDestroy { ngOnInit() {...} ngOnDestroy() {...} }

Slide 15

Slide 15 text

Component @Component({ selector: 'app-root', template: `

Hello, {{ title }} !

`, }) export class AppComponent { title = 'Angular'; } 15

Slide 16

Slide 16 text

Decorator 16 @Component({ selector: 'app-sample', template: `

Hello, {{ title }} !

`, }) export class SampleComponent { title = 'Angular'; }

Slide 17

Slide 17 text

tsconfig.json 17 { "compilerOptions": { "target": "es5", "experimentalDecorators": true } }

Slide 18

Slide 18 text

Decorators 18 ● @Component ● @Directive ● @Pipe ● @Injectable ● @Input / @Output

Slide 19

Slide 19 text

Generics 19 @Component({ selector: 'app-button', template: ` Click ` }) export class SampleComponent { @Output() clickButton = new EventEmitter(); }

Slide 20

Slide 20 text

Example: Dependency injection 20 @Injectable() export class UserService { constructor(private http: HttpClient) {} fetchUsers() { return this.http.get('/users'); } }

Slide 21

Slide 21 text

Example: RxJS 21 const a: Todo = { id: 1, text: 'aaa', enabled: false }; const b: Todo = { id: 2, text: 'bbb', enabled: true }; const todos$ = from([a, b]); // Observable todos$.pipe( filter(todo => todo.enabled), map(todo => todo.text) ).subscribe(text => console.log(text)); // 'bbb'

Slide 22

Slide 22 text

22 https://next.angular.io/getting-started

Slide 23

Slide 23 text

for backend? 23

Slide 24

Slide 24 text

24 https://nestjs.com

Slide 25

Slide 25 text

25

Slide 26

Slide 26 text

Controller 26 @Controller('cats') export class CatsController { @Get() findAll(): string { return 'This action returns all cats'; } }

Slide 27

Slide 27 text

Entity (TypeORM) 27 @Entity() export class Photo { @PrimaryGeneratedColumn() id: number; @Column({ length: 500 }) name: string; }

Slide 28

Slide 28 text

@puku0x Noriyuki Shinpuku ng-fukuoka organizer Thank you! 28