提供的参数与调用目标的任何签名都不匹配(react-mock-store)

时间:2017-05-24 00:11:21

标签: reactjs typescript

得到以下错误,我不明白,因为它似乎与匹配签名

  

[ts]提供的参数与呼叫目标的任何签名都不匹配。   const mockStore :(状态?:{       todo:string []; } | undefined)=> IStore< {       todo:string []; }>

import configureMockStore from 'redux-mock-store'

type MyStore = {
    todo: string[];
}

const mockStore = configureMockStore<MyStore>([]);

let storeVar : MyStore = {todo: ['one','two']};
const store = mockStore<MyStore>(storeVar);

redux-mock-store的typedef来自DefinitivelyTyped

// Type definitions for Redux Mock Store v0.0.6
// Project: https://github.com/arnaudbenard/redux-mock-store
// Definitions by: Marian Palkus <https://github.com/MarianPalkus>, Cap3 <http://www.cap3.de>
// Definitions: https://github.com/borisyankov/DefinitelyTyped

///<reference types="redux" />

declare module 'redux-mock-store' {
    import * as Redux from 'redux'

    function createMockStore<T>(middlewares?: Redux.Middleware[]): mockStore<T>;

    export type mockStore<T> = (state?: T) => IStore<T>;

    export interface IStore<T> {
        dispatch(action: any): any;
        getState(): T;
        getActions(): any[];
        clearActions(): void;
        subscribe(listener: Function): Function;
    }

    export default createMockStore
}

1 个答案:

答案 0 :(得分:1)

调用mockStore时,您不必指定类型参数。 createMockStore已经返回填充类型为mockStore的内容:

const store = mockStore(storeVar);