[英]How to declare React.Component type from external module with separate declaration file?
[英]How to declare the module type of an react component for flowtype, without breaking the formatter?
我定义了一个react组件,并使用流程对其进行检查:
/** @flow */
/** @jsx React.DOM */
var React = require('react');
var Hello = React.createClass({
propTypes: {
content: React.PropTypes.string.isRequired
},
render: function() {
return (
<section>hello</section>
);
}
});
module.exports = Hello;
但是流程报告了一个错误:
/Users/twer/workspace/yyy/a.js:16:16,20: ReactElement
Missing annotation
因为流需要一个具有明确类型的模块: http : //flowtype.org/docs/type-annotations.html#module-boundaries
对于react组件,我需要在render
方法上声明类型,所以我必须像这样修复它:
render: function(): ?ReactElement {
return (
<section>hello</section>
);
}
问题是,它会破坏我的想法的格式(因为?
的?ReactElement
)
还有其他地方放?ReactElement
吗?
我确定您现在已经找到了一些解决方案,但请注意?
是可选的。
render: function(): React.Element {
// ...
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.