2017-09-25 53 views
0

我得到了以下錯誤而設置reuder之一,打字稿無法設置初始狀態爲減速

/Users/Lxinyang/Desktop/angular/breakdown/ui/app/src/reducers/filters.spec.ts 
(12,9): error TS2345: Argument of type '{}' is not assignable to parameter of type '{ selectionState: { source: string; timeRange: Date[]; }; } | undefined'. 
    Type '{}' is not assignable to type '{ selectionState: { source: string; timeRange: Date[]; }; }'. 
    Property 'selectionState' is missing in type '{}'. 

的減速機的代碼,

const DATE_IN_MILLISECONDS = 60 * 60 * 24 * 1000 
const todayDate = new Date() 
const startDate = new Date(todayDate.getTime() - 6 * DATE_IN_MILLISECONDS) 
const defaultFiltersState = { 
    selectionState: { source: 'all', timeRange: [startDate, todayDate] } 
} 

export function filters(state = defaultFiltersState, action: any) {} 

我不知道爲什麼我我有這個問題,因爲我從未將{}分配到默認狀態。下面

代碼爲根,

export default combineReducers({ dataSource, filters, filtersVideo }) 

回答

0

原因是我設置空{}狀態而創建存儲,

const configureStore = (initialState: any) => { 
    return createStore(rootReducer, initialState, applyMiddleware(thunk)) 
} 

當應用程序初始化,

const store = configureStore({})