Skip to content

Instantly share code, notes, and snippets.

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',
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;
interface User {
readonly id: number;
readonly name: string;
readonly wifeName: string;
readonly parents: ReadonlyArray<string>;
}
const user: User = {
id: 1,
name: "John",
const numbers: ReadonlyArray<number> = [1, 2, 3, 4, 5];
numbers.push(6); // Property 'push' does not exist on type 'ReadonlyArray<number>'
const numbers: number[] = [1, 2, 3, 4, 5];
numbers.push(6); // There is nothing wrong with this
interface User {
readonly id: number;
name: string;
}
const user: User = {
id: 1,
name: "Keerati"
};
interface User {
id: number;
name: string;
}
const user: User = {
id: 1,
name: "Keerati"
};
const iAmAwesome = true;
iAmAwesome = false; // Cannot assign to 'iAmAwesome' because it is a constant
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),
const observable = of('response')
const result = await getValue(observable)
// Do the logic with the result
// .................
// .................
// .................