I have a simple Rxjs function involving observables and operators to return a new observable. In my code, I am using filter and map operators chained inside a pipe. Unfortunately, I am receiving the error TS2571: Object is of type 'unknown' inside the filter operator for data. The code is as follows:
import { filter, map, Observable } from 'rxjs'
@Component({
selector: 'app-observable-operator',
templateUrl: './observable-operator.component.html',
styleUrls: ['./observable-operator.component.css']
})
export class ObservableOperatorComponent{
title:string='Angular Observable using Observable Operators';
ob=new Observable((observer:any)=>{
console.log("Observable Starts");
observer.next(1)
observer.next(2)
observer.next(3)
observer.next(4)
observer.next(5)
observer.complete()
}).pipe(filter(data=>
data > 2), //Error inside filter operator (parameter) data:unknown
map((val)=>{return val as number*2}),
)
}