Flowtype在module.hot.accept上引发错误

Vak*_*lov 6 webpack flowtype webpack-dev-server

我正在尝试使用flowtype检查一些代码:

export default function configureStore(initialState: initialStateType) {
    /* ... */
    if (module && module.hot) {
        module.hot.accept('../reducers', () => {
            const nextRootReducer = require('../reducers');
            store.replaceReducer(nextRootReducer);
        });
    }
    /* ... */
}
Run Code Online (Sandbox Code Playgroud)

我收到此错误消息:

src/store/configureStore.js:14
 14:    module.hot.accept('../reducers', () => {
        ^ call of method `accept`. Method cannot be called on
 14:        module.hot.accept('../reducers', () => {
            ^^^^^^^^^^ property `hot` of unknown type
Run Code Online (Sandbox Code Playgroud)

我怎样才能解决这个问题?

谢谢!

小智 9

您需要将以下声明添加到您在.flowconfig的[libs]部分中指向的文件中.您可以在此处找到有关添加库定义文件的更多信息:https://flow.org/en/docs/libdefs/

declare var module : {
  hot : {
    accept(path:string, callback:() => void): void;
  };
};
Run Code Online (Sandbox Code Playgroud)