PyCharm 2016.3 Help

Using the Flow Type Checker

PyCharm provides basic support of Flow static type checker that brings type annotations to JavaScript. This support involves recognition and syntax highlighting of Flow structures on all operating systems. If you are using Unix or OS X, you can also run Flow in the command-line mode.

On this page:

Before you start

  1. Install and enable the NodeJS repository plugin as described in Installing, Updating and Uninstalling Repository Plugins and Enabling and Disabling Plugins.
  2. Download and install the Node.js runtime environment.
  3. Configure the Node.js interpreter in PyCharm:
    1. Open the Settings / Preferences Dialog by choosing File | Settings for Windows and Linux or PyCharm | Preferences for OS X, and click Node.js and NPM under Languages&Frameworks.
    2. On the Node.js and NPM page that opens, specify the location of the desired Node.js interpreter.
    See Configuring Node.js Interpreters for details.

Installing Flow

The easiest way to install the Flow type checker is to use the Node Package Manager (npm), which is a part of Node.js. See Installing and Removing External Software Using Node Package Manager for details.

Depending on the desired location of the Flow type checker executable file, choose one of the following methods:

  • Install the type checker globally at the PyCharm level so it can be used in any PyCharm project.
  • Install the type checker in a specific project and thus restrict its use to this project.
  • Install the type checker in a project as a development dependency.

In either installation mode, make sure that the parent folder of the Flow type checker is added to the PATH variable. This enables you to launch the type checker from any folder.

PyCharm provides user interface both for global and project installation as well as supports installation through the command line.

Installing Flow globally

Global installation makes a type checker available at the PyCharm level so it can be used in any PyCharm project. Moreover, during installation the parent folder of the type checker is automatically added to the PATH variable, which enables you to launch the type checker from any folder. To install the type checker globally, do one of the following:

  • Run the installation from the command line in the global mode:
    1. Launch the embedded Terminal by hovering your mouse pointer over /help/img/idea/show_tool_window_bars.png in the lower left corner of PyCharm and choosing Terminal from the menu (see Working with Embedded Local Terminal for details).
    2. Switch to the directory where NPM is stored or define a PATH variable for it so it is available from any folder, see Installing NodeJs.
    3. Type the following command at the command line prompt:
      npm install -g flow-bin

      The -g key makes the type checker run in the global mode. Because the installation is performed through NPM, the Flow type checker is installed in the npm folder. Make sure this parent folder is added to the PATH variable. This enables you to launch the type checker from any folder.

      For more details on the NPM operation modes, see npm documentation. For more information about installing the Flow type checker, see https://npmjs.org/package/flow-bin.

  • Run NPM from PyCharm using the Node.js and NPM page of the Settings dialog box.
    1. Open the Settings / Preferences Dialog by pressing Ctrl+Alt+S or by choosing File | Settings for Windows and Linux or PyCharm | Preferences for OS X, and click Node.js and NPM under Languages&Frameworks.
    2. On the Node.js and NPM page that opens, the Packages area shows all the Node.js-dependent packages that are currently installed on your computer, both at the global and at the project level. Click /help/img/idea/new.png.
    3. In the Available Packages dialog box that opens, select the required package to install.
    4. Select the Options check box and type -g in the text box next to it.
    5. Optionally specify the product version and click Install Package to start installation.

Installing Flow in a project

Installing a type checker in a specific project restricts its use to this project. To run project installation, do one of the following:

  • Run the installation from the command line:
    1. Launch the embedded Terminal by hovering your mouse pointer over /help/img/idea/show_tool_window_bars.png in the lower left corner of PyCharm and choosing Terminal from the menu (see Working with Embedded Local Terminal for details).
    2. Switch to the project root folder and type the following command at the command line prompt:
      npm install flow-bin
  • Run NPM from PyCharm using the Node.js and NPM page of the Settings dialog box.
    1. Open the Settings / Preferences Dialog by pressing Ctrl+Alt+S or by choosing File | Settings for Windows and Linux or PyCharm | Preferences for OS X, and click Node.js and NPM under Languages & Frameworks.
    2. On the Node.js and NPM page that opens, the Packages area shows all the Node.js-dependent packages that are currently installed on your computer, both at the global and at the project level. Click /help/img/idea/new.png.
    3. In the Available Packages dialog box that opens, select the required package.
    4. Optionally specify the product version and click Install Package to start installation.

Project level installation is helpful and reliable in template-based projects of the type Node Boilerplate or Node.js Express, which already have the node_modules folder. The latter is important because NPM installs the Flow type checker in a node_modules folder. If your project already contains such folder, the Flow type checker is installed there.

Projects of other types or empty projects may not have a node_modules folder. In this case npm goes upwards in the folder tree and installs the Flow type checker in the first detected node_modules folder. Keep in mind that this detected node_modules folder may be outside your current project root.

Finally, if no node_modules folder is detected in the folder tree either, the folder is created right under the current project root and the Flow type checker is installed there.

In either case, make sure that the parent folder of the Flow type checker is added to the PATH variable. This enables you to launch the type checker from any folder.

For more details, see Getting Started with Flow.

Configuring Flow in PyCharm

To have PyCharm recognize Flow structures, provide correct syntax highlighting, report errors properly, and avoid false-positive error highlighting, change the JavaScript language level to Flow:

  1. Open the Settings / Preferences Dialog by pressing Ctrl+Alt+S or by choosing File | Settings for Windows and Linux or PyCharm | Preferences for OS X, and click JavaScript under Languages&Frameworks.
  2. On the JavaScript page that opens, choose Flow from the JavaScript Language Version drop-down list.
  3. In the Flow executable field, specify the path to the Flow executable file.
  4. Specify how you want references resolved by selecting or clearing the Resolve using Flow when possible check box:
    • When this check box is selected, suggestion lists for reference resolution contain both suggestions retrieved from integration with Flow and suggestions calculated by PyCharm.
    • When the check box is cleared, references are resolved through PyCharm calculation only.

See Also

Last modified: 23 November 2016