使用 redux-thunk 和 redux-mock-store 1.5.4 版本 2.x.x 时,此代码可以工作:
import configureMockStore from 'redux-mock-store';
import thunk from 'redux-thunk';
const mockStore = configureMockStore([thunk]);
...但是将 redux-thunk 更新到 3.x.x 后会产生错误:
Type 'typeof import("/Users/user/Development/web-client/node_modules/redux-thunk/dist/redux-thunk")' is not assignable to type 'Middleware<{}, any, Dispatch<AnyAction>>'.
Type 'typeof import("/Users/user/Development/web-client/node_modules/redux-thunk/dist/redux-thunk")' provides no match for the signature '(api: MiddlewareAPI<Dispatch<AnyAction>, any>): (next: Dispatch<AnyAction>) => (action: any) => any'.ts(2322)
我当然可以理解为什么,
redux-thunk.d.ts
中的类型信息在 v3 和 v2 中截然不同。我无法找到任何特定于将 v3 与 redux-mock-store 一起使用的信息。
我知道建议是不再使用模拟商店,但我的直接任务是更新软件包。
有没有办法将 redux-thunk v3.x.x 与 redux-mock-store 一起使用?
...结果很简单并且有记录。我必须改变这个:
import thunk from 'redux-thunk';
对此:
import { thunk } from 'redux-thunk';
这是在文档中,但线条看起来非常相似,我没有注意到变化。