减速机类型

时间:2016-04-26 10:33:15

标签: javascript reactjs typescript redux react-redux

我无法理解如何处理Redux的新版本。 现在我正在尝试完成本教程https://maxfarseer.gitbooks.io/redux-course-ru/content/index.html

此时我正在"创建商店"以下简单代码: 存储/ configureStore.ts

import {createStore, Reducer} from 'redux';
import rootReducer from '../reducers';

export default function configureStore(initialState) {
    const store = createStore(rootReducer, initialState);

    if (module.hot) {
        module.hot.accept('../reducers', () => {
            const nextRootReducer=require('../reducers');
            store.replaceReducer(nextRootReducer);
        })
    }

    return store;
}

当我尝试编译时,它会向我发送有关此错误的消息:

 ERROR in ./src/store/configureStore.ts
    (10,34): error TS2345: Argument of type '{}' is not assignable to parameter of type '<A extends Action>(state: any, action: A) => any'.
      Type '{}' provides no match for the signature '<A extends Action>(state: any, action: A): any'

这是我的减速器索引文件

import {combineReducers} from "redux/index";
import page from './page';
import user from './user';

    const rootReducer = combineReducers({
        page,
        user
    });

    export default rootReducer;

//page.ts
const initialState = {
    year: 2016,
    photos: []
};

function page(state = initialState,
              action = {type: '', payload: null}) {
    return state
}

export default page;

//user.ts
const initialState = {
    name: 'Аноним'
};

export default function user(state = initialState,
                                action = {type: '', payload: null}) {
    return state
}

0 个答案:

没有答案