Trying to incorporate an array into my store is causing issues with the following error popping up at
tasks: payload.payload ? [ ...state, payload.payload ] : []
: Error:(22, 35) TS2461: Type 'ITask' is not an array type
. Any suggestions on how to resolve this?
import * as TaskActions from './task.actions';
import { Action, createReducer, on } from '@ngrx/store';
import { ITask } from '../../models/task';
export interface State {
task: ITask | null;
error: any;
}
const initialState: ITask = {
basketTotal: 0,
carePlanPrice: 0,
category: null,
completionDate: null
};
export const taskReducer = createReducer(
initialState,
on(TaskActions.getData, state => ({ ...state })),
on(TaskActions.dataReceived, (state, payload) => ({
...state,
tasks: payload.payload ? [ ...state, payload.payload ] : []
})),
on(TaskActions.dataNotReceived, state => ({ ...state })),
on(TaskActions.signOut, state => ({ ...state })),
on(TaskActions.signOutSuccess, state => ({ ...state, ...initialState })),
);
export function reducer(state: ITask | undefined, action: Action) {
return taskReducer(state, action);
}
Snapshot: