Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/379.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/reactjs/22.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript Flow、ReactJS和ES6类出错_Javascript_Reactjs_Flowtype - Fatal编程技术网

Javascript Flow、ReactJS和ES6类出错

Javascript Flow、ReactJS和ES6类出错,javascript,reactjs,flowtype,Javascript,Reactjs,Flowtype,为什么这些错误会显示在流中。我在ES6课程中使用React。代码示例如下: 更新 基于这个例子,我几乎可以做到这一点: 我消除了大部分的流错误,但现在应用程序运行时失败了。我认为这不是剥离流或巴贝尔类的东西。如果在下面的代码中注释掉流类型defs,则不会出现此错误 我正在用watchify-t[babelify]app.js-o./build/app.js运行我的应用程序 合成错误: /Users/carlf/Documents/dev/reactjs/flyteet/app/views/po

为什么这些错误会显示在
中。我在ES6课程中使用React。代码示例如下:

更新

基于这个例子,我几乎可以做到这一点:

我消除了大部分的流错误,但现在应用程序运行时失败了。我认为这不是剥离流或巴贝尔类的东西。如果在下面的代码中注释掉流类型defs,则不会出现此错误

我正在用
watchify-t[babelify]app.js-o./build/app.js运行我的应用程序

合成错误: /Users/carlf/Documents/dev/reactjs/flyteet/app/views/posts/MyNewPostForm.js: 缺少类属性转换。分析文件时: /Users/carlf/Documents/dev/reactjs/flyteet/app/views/posts/MyNewPostForm.js

流量错误:

app/views/posts/MyNewPostForm.js:51:var myPostTxt= ReactDOM.findDOMNode(this.Refs.content).value; ^^^^属性
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.
  }

唯一的流量错误可能是
Refs
中的大写字母R?
在您提供的代码中,它是小写的,但在错误消息中它是大写的。

使用flow创建组件时,您必须在类声明中提供类型参数,以描述道具、默认道具和状态的类型。我在这里遵循官方的flow/React ES6示例,但也无法实现这一点:另外让我恼火的是,JS文件上的非React运行流在添加类型批注之前不会显示任何错误。但是React ES6迫使我添加类型批注。是的,这是正确的答案。类属性区分大小写