getting TypeError: .finalize is not a function in Rxjs6

getting TypeError: .finalize is not a function in Rxjs6

在以下函数中,出现运行时错误 TypeError: this.authService.authServiceSigninUser(...).map(...).catch(...).finalize is not a function

问题 1) 为什么 Typescript 在编译时没有捕捉到这个错误?我怎么能在编译时捕获这个错误。

问题2)如何解决这个错误?我尝试同时使用 finallyfinalize,但两者都不起作用。

public signinUser(user:UserSigninInfo):any{

    this.loaderService.show(); //this shows a spinner
    return this.authService.authServiceSigninUser(user)
      .map(response=>{
        console.log('response from backend service',response);
        let result= <HttpResponse<any>>response; 
        let authToken = result.headers.get("x-auth-token")
        if(authToken == null) {
          console.log("no authToken")
        } else {
          console.log("authToken is ",authToken)
          localStorage.setItem('id_token', authToken);
        }
        return result;
      })
      .catch(this.handleError)
    .finally(()=> this.loaderService.hide()) //hide the spinner
  }

在你的组件中导入这一行

从 'rxjs/operators' 导入 {finalize,catchError,tap};

试试这个代码

 public signinUser(user:UserSigninInfo):any{

    this.loaderService.show(); //this shows a spinner
    return this.authService.authServiceSigninUser(user)
      .pipe(tap(response=>{
        console.log('response from backend service',response);
        let result= <HttpResponse<any>>response; 
        let authToken = result.headers.get("x-auth-token")
        if(authToken == null) {
          console.log("no authToken")
        } else {
          console.log("authToken is ",authToken)
          localStorage.setItem('id_token', authToken);
        }
        return result;
      })
      ,catchError(this.handleError)
    ,finalize (()=> this.loaderService.hide())); //hide the spinner
  }