Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Flow type checking performance in VSCode

I've built a new project using create-react-app and wanted to start it using a static type checking, there are two choices now in market:

  • TypeScript
  • Flow

I kind want to go with Flow just because it's also built by Facebook and should(?) have better support for a React project.

So what I'm struggling it is type-checking performance in VSCode. Once I created my project, I ran the following commands:

  1. yarn add -D eslint-plugin-prettier husky prettier pretty-quick babel-eslint eslint-plugin-flowtype flow-bin eslint
  2. Added Airbnb React style: eslint --init
  3. Ran flow init
  4. Installed Flow Language Support
  5. Disabled JavaScript and TypeScript language support as recommended
  6. Added following config to my Workspace settings:

-

{
  "flow.useNPMPackagedFlow": true,
  "flow.pathToFlow": "${workspaceRoot}/node_modules/.bin/flow"
}

My .eslintrc is as follows:

{
  "extends": ["airbnb", "plugin:flowtype/recommended"],
  "plugins": ["prettier", "flowtype"],
  "parser": "babel-eslint",
  "env": {
    "browser": true,
    "es6": true,
    "jest": true,
    "node": true
  },
  "rules": {
    "react/jsx-filename-extension": [1, { "extensions": [".js", ".jsx"] }],
    "prettier/prettier": [
      "error",
      {
        "printWidth": 80,
        "singleQuote": true,
        "useTabs": false,
        "tabWidth": 2,
        "semi": true,
        "bracketSpacing": true
      }
    ]
  },
  "settings": {
    "import/resolver": {
      "node": {
        "paths": ["src"]
      }
    }
  }
}

However Flow seems to be quite slow on my machine, I have added a simple function to my App.js:

const sum = (a: number, b: number) => a + b;
sum(1, '12323');

And it takes up to 10 seconds to validate my code which is quite a bummer. Is there a way to speed this up?

Maybe it's worth to start with TypeScript and don't bother with Flow?

like image 362
Evaldas Buinauskas Avatar asked Mar 25 '18 19:03

Evaldas Buinauskas


1 Answers

There are some open issues regarding possible memory leaks and performance related problems with flow, some links below:

https://github.com/facebook/flow/issues/2152

https://github.com/flowtype/flow-bin/issues/70

Both tools are great and have their pros and cons, I would personally recommend to give a try to TypeScript too and perform a comparison yourself.

In my own experience on a large code base I have found TypeScript:

  • more performant
  • more types for external libraries
  • larger community
like image 89
GibboK Avatar answered Nov 08 '22 13:11

GibboK