我使用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},则错误消失了。
如果尝试访问有效负载属性,我也会收到打字稿错误。
答案 0 :(得分:2)
所有动作都必须具有type
属性以标识它们。查看错误日志,您的操作仅包含有效负载。确保LoginSuccessAction
和LogOutAction
都具有只读的type
属性。示例:
class LoginSuccessAction extends Action {
readonly type = "LOGIN_SUCCESS";
}