Flow,ReactJS和ES6类的错误

时间:2016-06-04 03:48:21

标签: javascript reactjs flowtype

为什么这些错误会显示flow。我正在使用React和ES6类。代码示例如下:

更新

基于这个例子,我几乎得到了这个工作: https://flowtype.org/docs/react.html#defining-components-as-react-component-subclasses

我摆脱了大部分Flow错误,但现在app在运行时失败了。我认为这是ReactJS没有剥离Flow或Babel类的东西。如果我在下面的代码中注释掉Flow类型defs,我不会收到此错误。

我正在使用watchify -t [ babelify ] app.js -o ./build/app.js

运行我的应用
  

语法错误:   /Users/carlf/Documents/dev/reactjs/FlyTweet/app/views/posts/MyNewPostForm.js:   缺少类属性转换。在解析文件时:   /Users/carlf/Documents/dev/reactjs/FlyTweet/app/views/posts/MyNewPostForm.js

流程错误:

  

app / views / posts / MyNewPostForm.js:51 51:var myPostTxt =   ReactDOM.findDOMNode(this.Refs.content)。价值;                                                      ^^^^属性Refs。在15中找不到属性:导出默认类MyNewPostForm   扩展React.Component {                             ^^^^^^^^^^^^^ MyNewPostForm

来自 package.json

  "dependencies": {
    "babel-preset-react": "6.5.0",
    "babelify": "7.3.0",
    "react": "15.1.0",
    "react-dom": "15.1.0",
    "react-router": "2.4.1"
  }

反应组件

export default class MyNewPostForm extends React.Component {

  // START Flow type definitions.
  MAX_POST_CHARS: number; 

  state: {
      charsRemaining: number,
      SendButtonDisabled: boolean
  };

  handleChange: () => void;
  onSubmit: () => void;
  // END Flow type definitions.

  constructor() {
    super();

    this.MAX_POST_CHARS = 139;

    this.state = {
        charsRemaining: this.MAX_POST_CHARS,
        SendButtonDisabled: true
    };

   this.handleChange = this.handleChange.bind(this);    
   this.onSubmit = this.onSubmit.bind(this);    

  }

  handleChange() {
     var myPostTxt = ReactDOM.findDOMNode(this.refs.content).value;

     // Do something here.
  }

1 个答案:

答案 0 :(得分:1)

可能唯一的流量错误是jQuery(window).bind("load", function()中的大写字母R? 在您提供的代码中它是小写的,但在错误消息中它是大写。