In Nov. 2014, 3 months ago, Facebook open-sourced a new command line tool, a static type checker called "Flow". Now I want to run it on a few of my older, existing javascript files. These contain references to the jQuery library.
My JS files were not written with static type-checking in mind. however, after including /* @flow */ at the top of the file, when I run flow with this Command:
flow myfile.js
Result:
/var/www/myfilejs:70:12,17: identifier jQuery
Unknown global name
Found 1 error
As I understand it, the way to include jQuery into Flow's type checking process is to create an "interface file".
Has anyone done this yet for the jQuery library? (I use jQuery 1.9)
If you want an actual jQuery flow interface definition, you can look at the one provided in https://github.com/marudor/flowInterfaces.
Install it with:
npm install --save-dev iflow-jquery
or
yarn add --dev iflow-jquery
And then add the following to your .flowconfig
file:
[libs]
node_modules/iflow-jquery/index.js.flow
After that, flow will infer the types of the parameters you provide to jquery functions, and will warn you if you are passing the incorrect types.