In my angular 2 I use ngrx and have some actions and reducers. Example of actions :
import { Action } from '@ngrx/store';
export const actionTypes = {
ACTION_1: type('Actions 1'),
ACTION_2: type('Actions 2'),
};
export class ActionOne implements Action {
public type = actionTypes.ACTION_1;
constructor(public payload: any) { }
}
export class ActionTwo implements Action {
public type = actionTypes.ACTION_2;
}
export type Actions
= ActionOne
| ActionTwo;
So, some actions has payload, others - no, and Actions is union type, which can be ActionOne or ActionTwo. But in me reducer I have an error: Property 'payload' does not exist on type 'Actions' Property 'payload' does not exist on type 'ActionTwo'.
Reducer is like this:
export function reducer(state = initialState, action: Actions): IState {
switch (action.type) {
case actions.actionTypes.ACTION_1: {
return Object.assign({}, state, {
data: action.payload,
});
}
case ...
}
}
I got this error after updating typescript version from 2.0.3 to 2.2.2.
So, is there way to fix error without putting payload to every action? May be is there some option from tsconfog.json for this case?