Here is the code snippet from a components.ts file in an Angular project. I encountered the following error during compilation:
ERROR
merge/merge.component.ts:75:12 - error TS2551: Property 'unsubscribe' does not exist on type 'Observable'. Did you mean 'subscribe'?
75 out$().unsubscribe() ~~~~~~~~~~~
../../node_modules/rxjs/dist/types/internal/Observable.d.ts:53:5 53 subscribe(observer?: Partial<Observer>): Subscription; ~~~~~~~~~ 'subscribe' is declared here.
import { Component, ElementRef, OnDestroy, OnInit, ViewChild } from '@angular/core';
import { defer, Observable, of, Subscription } from 'rxjs';
import { HttpClient } from '@angular/common/http';
import {filter,map,distinctUntilChanged,distinctUntilKeyChanged, mergeAll, mergeMap, concatAll, retry, repeat} from 'rxjs/operators'
import {from} from 'rxjs';
@Component({
selector: 'app-merge',
templateUrl: './merge.component.html',
styleUrls: ['./merge.component.scss']
})
export class MergeComponent implements OnInit {
public items:any[]=[];
constructor(private http: HttpClient){}
ngOnInit(): void {
let counter=1;
const out$=()=> defer(()=>this.http.get('https://jsonplaceholder.typicode.com/todos/'+counter++)).pipe(
repeat(4)
);
out$().subscribe(
data => console.log(data)
)
out$().unsubscribe()
}
}