Flow
Flow is a static type checker that brings type annotations to JavaScript. WebStorm recognizes Flow structures and provides syntax highlighting for them on all operating systems.
Installing Flow
-
In the embedded Terminal (Alt+F12), type one of the following commands:
-
npm install --global flow-bin
to install Flow globally. -
npm install --save-dev flow-bin
to install Flow as a development dependency.
-
Configuring Flow in WebStorm
To have WebStorm recognize Flow structures, provide correct syntax highlighting, report errors properly, and avoid false-positive error highlighting, change the JavaScript language level to Flow, add a .flowconfig configuration file to your project, and supply every file to be checked with a // @flow
comment on top.
To change the language level to Flow
-
In the Settings/Preferences dialog (Ctrl+Alt+S), go to . The JavaScript page opens.
From the JavaScript Language Version list, choose Flow.
-
In the Flow package or executable field, specify the path to the node_modules\flow-bin node_modules/flow-bin package or the Flow binary executable file. To use node_modules\.bin\flownode_modules/ .bin/flow make sure the path to Node.js is added to the
PATH
environment variable. -
In the Use Flow server for: area, specify the basis for coding assistance by selecting or clearing the following checkboxes:
Type checking: When this checkbox is selected, syntax and error highlighting is provided based on the data received from the Flow server. When the checkbox is cleared, only the basic internal WebStorm highlighting is available.
Navigation, code completion, and type hinting: When this checkbox is selected, suggestion lists for reference resolution and code completiong contain both suggestions retrieved from integration with Flow and suggestions calculated by WebStorm. When the checkbox is cleared, references are resolved through WebStorm calculation only.
Keep the Save all modified files automatically checkbox selected to ensure that Flow is applied continuously because Flow checks the current files only after all the other modified files are saved.
To generate a .flowconfig configuration file in your project
-
In the embedded Terminal (Alt+F12), type:
flow init
To enable Flow in a file
-
Add a
// @flow
comment at the top of it: just typeflow
, press Tab, and WebStorm will expand it into// @flow
.