Effect dispatched an invalid action:

£可爱£侵袭症+ 提交于 2019-12-24 19:27:32

问题


I use Angular 7.1.4

My Effect:

@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)))
        );
    })
  );
}

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

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

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


回答1:


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";
}


来源:https://stackoverflow.com/questions/54481888/effect-dispatched-an-invalid-action

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!