我在我的React项目中使用material-ui
。我正在尝试将Flow引入混音。
一个例子:
import Paper from 'material-ui/Paper';
type Props = {
ruleName: string,
rules: Object[],
actions: string[],
allowSubmit: boolean,
onSubmit: ?Function,
}
const NotifyRule = (props: Props) => (
<Paper style={{ padding: 10, width: '100%' }}>
....
</Paper>
);
我尝试将material-ui的定义写为
declare module 'material-ui' {
declare type Paper = any;
declare var exports: 'material-ui';
}
这不起作用。我失败了:
import Paper from 'material-ui/Paper';
^^^^^^^^^^^^^^^^^^^ material-ui/Paper. Required module not found
有关解决此问题的任何指示都非常有用。
答案 0 :(得分:2)
您必须单独声明子模块以使流识别它:
declare module 'material-ui/Paper' {
declare var exports: any;
}
declare module 'material-ui' {
// Note: That export value looks weird to me, but whatever
declare var exports: 'material-ui';
}
我们在flow-typed
存储库中使用了redux-saga做了类似的事情......也许你在那里得到了一些灵感: - )