2017-09-13 57 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

相關問題