2017-09-13 119 views
0

我正在使用Ngrx 4.03和typeScript 2.5.2。TypeScript编译器错误地报告action.payload不存在

我已经定义了一个行动,例如:

import { Action } from '@ngrx/store'; 
import { IUser } from '../models'; 

export const LOGIN_SUCCESS = '[Auth] Login Success'; 
export const LOGOUT_SUCCESS = '[Auth] Logout Success'; 

export class LoginSuccess implements Action { 
    readonly type = LOGIN_SUCCESS; 

    constructor (
    public payload: IUser 
) {} 
} 

export class LogoutSuccess implements Action { 
    readonly type = LOGOUT_SUCCESS; 
} 

export type AuthActions 
= LoginSuccess 
| LogoutSuccess; 

在我相应的减速,打字稿告诉我,action.payload上不存在Action,即使我可以登录值就好了。我究竟做错了什么?

+1

我将呈现减速,如果这是错误所在。 – Meeker

回答

0

我几乎可以肯定,如果你有一个动作(或更多)没有有效载荷,它会引入这种行为。

所以更改此代码:

export class LogoutSuccess implements Action { 
    readonly type = LOGOUT_SUCCESS; 
} 

export class LogoutSuccess implements Action { 
    readonly type = LOGOUT_SUCCESS; 

    constructor(public payload: null) 
} 
+0

这是我第一次尝试,无济于事。 – Brandon

+0

你可以只用:'constructor(){}'并且让我知道 – Maxime

+0

当然。目前我在一个不同的项目上猛烈抨击,但今天的某个时候应该能够回到这一点。 – Brandon