error TypeError: Cannot read property 'pipe' of undefined ngxs logout

error TypeError: Cannot read property 'pipe' of undefined ngxs logout

从 auth.state 我正在调用注销方法。我收到以下错误:

error TypeError: Cannot read property 'pipe' of undefined

@Action(Logout)
logout(ctx: StateContext<AuthStateModel>) {
  return this.loginService.logout().pipe(
    tap((result) => {
    const state = ctx.getState();
      ctx.setState({...state,
          loggedInUser:undefined,
          accessToken: undefined,
          username: undefined,
          email:undefined,
          roles:undefined,
        });
     })
  );
}

这是logOut方法

public logout(): Observable<void> {
   return this.tokenStorage.signOut();
}

这是localstorage

中的signOut方法
public signOut():any {
   return window.sessionStorage.clear();
}

错误图片:

您确定 window.sessionStorage.clear() 具有 return 值吗?

clear() 是一个无效的方法,这就是您收到该错误的原因。

您以后可以使用 console.log(window.sessionStorage.clear()) 简单地检查类似的问题,然后您将得到它是 return 的值还是未定义。

@Action(Logout)
logout(ctx: StateContext<AuthStateModel>) {
 this.loginService.logout()
    const state = ctx.getState();
      ctx.setState({...state,
          loggedInUser:undefined,
          accessToken: undefined,
          username: undefined,
          email:undefined,
          roles:undefined,
        });
        return state;
 };

我用这个替换了代码......谢谢你的帮助......我应该问另一个问题,上面这个......问题实际上是(属性管道在类型void上不存在)但我得到了有点迷失在代码中...... :)