I encountered an issue while trying to handle errors for a method in Angular. After adding a catchError check using the .pipe() method, I noticed that the variable roomId
was marked with a red squiggly line. The error message read:
TS2345: Argument of type 'unknown' is not assignable to parameter of type 'number'
This section shows where the error check is being performed.
this.firstRoom(room).pipe(
first(),
catchError((error: HttpErrorResponse)=>{
if(error.status != 200){
// handle error
}else{
// return error
return throwError(error);
}
}),
Below is the complete method.
public findRoom(room: Room): Observable<house> {
return new Observable(house =>{
this.firstRoom(room).pipe(
first(),
catchError((error: HttpErrorResponse)=>{
if(error.status != 200){
// handle error
}else{
// return error
return throwError(error);
}
}),
).subscribe(roomId =>
this.goToThisRoom(roomId).pipe( <----- roomId throws that argument type unknown
first()
).subscribe(roomInfo => {
if (roomInfo.status === "failed") {
house.next(house.failed);
} else {
this.downloadRoom(roomId).pipe(
first()
).subscribe(blobFile =>
this.getRoom(blobFile, name)
);
house.next(house.ready)
}
}
)
)
});
}
Do you have any insights into why this might be happening?