效果派出了无效的动作: [英] Effect dispatched an invalid action:

查看:56
本文介绍了效果派出了无效的动作:的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用Angular 7.1.4

I use Angular 7.1.4

我的效果:

@Injectable()
export class LoginEffects {
  constructor(private actions$: Actions, private authService: AuthenticationService) {
  }

  @Effect({dispatch: true})
  loginRequest$: Observable<any> = this.actions$.pipe(
    ofType(LoginActionsType.LOGIN_REQUEST),
    exhaustMap(payload => { // it might be switchMap, the error is the same.
      console.log(payload);
      return this.authService.login(payload.user, payload.password) // TypeScript Errors: Property 'user' does not exist on type 'never'. ; TS2339: Property 'password' does not exist on type 'never'.
        .pipe(
          map(user => new LoginSuccessAction(user)),
          catchError( err => of(new LogOutAction(err)))
        );
    })
  );
}

我收到此错误:错误错误:效果"LoginEffects.loginRequest $"调度了无效的操作:...

And i get this error: ERROR Error: Effect "LoginEffects.loginRequest$" dispatched an invalid action: ...

如果我在@Effect装饰器中添加{dispatch:false},则错误消失了.

If i add {dispatch: false} in the @Effect decorator, the error is gone.

如果尝试访问有效负载属性,我也会收到打字稿错误.

Also i get typescript errors if try to access payload properties.

推荐答案

所有操作都必须具有 type 属性才能识别它们.查看错误日志,您的操作仅包含有效负载.确保 LoginSuccessAction LogOutAction 都具有只读的 type 属性.示例:

All actions must have a type property to identify them. Looking at the error log your action only contains a payload. Make sure that LoginSuccessAction and LogOutAction both have a readonly type property. Example:

class LoginSuccessAction extends Action {
  readonly type = "LOGIN_SUCCESS";
}

这篇关于效果派出了无效的动作:的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆