This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import { Component, OnDestroy, OnInit } from '@angular/core'; | |
| import { Observable, Subscription } from 'rxjs'; | |
| export class RxJSUtil { | |
| static unsubscribe = (subscriptions: Subscription[]) => | |
| subscriptions.forEach(subscription => subscription.unsubscribe()); | |
| } | |
| @Component({ | |
| selector: 'nx-tutorial-root', |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| type DeepReadonlyObject<T> = { readonly [K in keyof T]: DeepReadonly<T[K]> }; | |
| type DeepReadonly<T> = T extends (infer E)[][] | |
| ? ReadonlyArray<ReadonlyArray<DeepReadonlyObject<E>>> | |
| : T extends (infer E)[] | |
| ? ReadonlyArray<DeepReadonlyObject<E>> | |
| : T extends object | |
| ? DeepReadonlyObject<T> | |
| : T; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| interface User { | |
| readonly id: number; | |
| readonly name: string; | |
| readonly wifeName: string; | |
| readonly parents: ReadonlyArray<string>; | |
| } | |
| const user: User = { | |
| id: 1, | |
| name: "John", |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| const numbers: ReadonlyArray<number> = [1, 2, 3, 4, 5]; | |
| numbers.push(6); // Property 'push' does not exist on type 'ReadonlyArray<number>' |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| const numbers: number[] = [1, 2, 3, 4, 5]; | |
| numbers.push(6); // There is nothing wrong with this |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| interface User { | |
| readonly id: number; | |
| name: string; | |
| } | |
| const user: User = { | |
| id: 1, | |
| name: "Keerati" | |
| }; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| interface User { | |
| id: number; | |
| name: string; | |
| } | |
| const user: User = { | |
| id: 1, | |
| name: "Keerati" | |
| }; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| const iAmAwesome = true; | |
| iAmAwesome = false; // Cannot assign to 'iAmAwesome' because it is a constant |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| const observable = of('response') | |
| function hasValue(value: any) { | |
| return value !== null && value !== undefined; | |
| } | |
| function getValue<T>(observable: Observable<T>): Promise<T> { | |
| return observable | |
| .pipe( | |
| filter(hasValue), |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| const observable = of('response') | |
| const result = await getValue(observable) | |
| // Do the logic with the result | |
| // ................. | |
| // ................. | |
| // ................. |