设置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 '{}'.
reducer的代码,
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 :(得分:0)
原因是我在创建商店时设置了空{}
状态,
const configureStore = (initialState: any) => {
return createStore(rootReducer, initialState, applyMiddleware(thunk))
}
当app init,
const store = configureStore({})