使用create-react-app + Flow的opaque类型

时间:2017-12-16 10:42:05

标签: reactjs flowtype create-react-app

首先,我想说,感谢您为这个令人惊叹的平台做出贡献,这让我有了很多次的帮助。用那个说:

我正面临着使用opaque类型别名的create-react-app和flow的挑战:https://flow.org/en/docs/types/opaque-types/

这是我的设置:

  1. create-react-app@1.4.3
  2. flow-bin@0.61.0
  3. Find screenshot of the version of my flow-bin here (used 'flow version')

    的package.json

    {
      "name": "reactProjectWithFlow",
      "version": "0.1.0",
      "private": true,
      "dependencies": {
        "grid-styled": "^2.0.0-11",
        "material-ui": "^0.19.4",
        "mobx": "^3.4.1",
        "mobx-react": "^4.3.5",
        "react": "^16.1.1",
        "react-dom": "^16.1.1",
        "react-scripts": "1.0.17"
      },
      "scripts": {
        "start": "react-scripts start",
        "build": "react-scripts build",
        "test": "react-scripts test --env=jsdom",
        "eject": "react-scripts eject"
      },
      "devDependencies": {
        "babel-cli": "^6.26.0",
        "babel-preset-flow": "^6.23.0",
        "flow-bin": "^0.61.0"
      }
    }
    

    我的编辑器是使用Nuclide包的Atom: https://nuclide.io/

    我发现了这个小小的甜点: https://flow.org/en/docs/tools/create-react-app/

    我遵循这种方法使其按照上一篇文章中的说法运行: https://flow.org/en/docs/install/

    当我跑步"纱线开始"这很好,很有效。 Flow也在编辑器中启动并运行。

    我想模拟我的类中的私有和公共字段,并发现这可以使用带有flow的opaque类型别名来完成,如上所述。

    当我尝试进行单一测试时,它是如何工作的(我是流动的新手),例如。

    opaque type ID = string;

    如果我把它放在一个源文件中,那么流程就可以了,或者更好的说,我没有得到任何流错误,但我的开发服务器抱怨:

    Find a screenshot here with the compilation error using opaque keyword

    当我省略opaque关键字时,如果工作正常。

    Find screenshot with working compilation when opaque is omitted

    我感谢你的支持,

    祝你好运

0 个答案:

没有答案
相关问题