Closed
Description
TypeScript Version:
2.0.0
Code
class ControllerSelectAction implements Action {
type: "CONTROLLER_SELECT";
payload: Controller;
}
export class ControllerRefreshAction implements Action {
type: "CONTROLLER_REFRESH";
}
type ControllerAction = ControllerSelectAction | ControllerRefreshAction;
const controllerReducer(state: any, action: ControllerAction) {
switch(action.type) {
case "CONTROLLER_REFRESH":
return state.set("refresh", true);
case "CONTROLLER_SELECT":
return state.update("selected", (controller) => controller.id === action.payload.id ? controller : action.payload));
}
Expected behavior:
action
should be narrowed to the ControllerSelectAction
class in the anonymous function in the CONTROLLER_SELECT
case, so that no error is thrown when accessing action.payload.id
.
Actual behavior:
The following error is thrown:
Property 'payload' does not exist on type 'ControllerSelectAction | ControllerRefreshAction