我使用 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$”调度了无效操作:...
如果我在 @Effect 装饰器中添加 {dispatch: false} ,错误就会消失。
如果尝试访问有效负载属性,我还会收到 typescript 错误。
最佳答案
所有操作都必须有一个 type
属性来标识它们。查看错误日志,您的操作仅包含有效负载。确保 LoginSuccessAction
和 LogOutAction
都具有只读 type
属性。示例:
class LoginSuccessAction extends Action {
readonly type = "LOGIN_SUCCESS";
}
关于javascript - Effect 调度了无效操作 :,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54481888/