Originally from: facebook/flow#284 (comment)
I use following solution which work great:
- .flowconfig file is placed to src folder.
- node_modules and flow-typed folders resides in root folder.
- Option all=true is enabled in .flowconfig file.
- flow-typed typings is included in .flowconfig file.
- Well-typed modules from node_modules folder that contain module own typings is included to .flowconfig file manually.
So .flowconfig file look like that:
[include]
../node_modules/mobx
../node_modules/other-well-typed-module-with-typings
[libs]
../flow-typed/npm
../flow-typed-generated-stubs/npm
[ignore]
# Nothing ignored
[options]
all=true
As a result:
- I do not need annotate any file with //@flow header. All my files are type-checked by default. So there are no more mess with forgotten headers and untyped files.
- Type declatations from flow-typed repository is supported. They are placed to flow-typed folder and can be downloaded automatically on each build.
- Well-typed modules that includes module own typings is also supported. Path to such modules is included in .flowconfig file.
- flow-typed declarations stubs is used for bad-typed modules. Generated or created declarations is placed to flow-typed-generated-stubs. So bad-typed modules do not affect type checking.
- No overhead on type-checking entire node_modules directory.
- I do not ignore anything by default. And that is good because in future I can use [ignore] section for excluding some module js-files if only some of module js-files is well-typed and other is bad-typed.
There are one disadvantage of described solution. I need to include all well-typed modules (in node_modules folder) to my .flowconfig file. It is not a big issue because there are only a few well-typed modules currently.
P.S. Do not try specifying more exact path for well-typed modules. For example, including ../node_modules/mobx/lib instead of ../node_modules/mobx is bad idea. It will not work. Currently I do not know the reason of that behavior.