I love typescript. But after I gave flow a try, it really makes things easier in terms of
react related thing. It could handle the redux immutable check and easy to start. But one problem is that sometimes you just can’t find type definition for the 3rd party libs as oppose to typescript, which is already widely adopted nowadays. So, how to solve it?
The solution is still the same, you simply create a definition for that module, and let it return
Suppose that we are using
no-where-to-find like this:
npm run flow will give you an error as:
no-where-to-find. Required module not found
Create a folder named
flow-typed at the root of the project.
Create a file which has the same name as the module, in the case:
Put the following content in it:
The fastest way:
Or you can declare the type by yourself if you know the signature.
You are good to go.
Install type definition for packages in
packages.json which could be found. And in fact, if it can’t find the definition, it will generate the mock typed definition like the one we did in part one.
Or you can install for a specific package.
You can update it as well
It will generate the mock type definition for the module
foo in the
/flow-typed/npm in order to prevent the
required module not found error.
flow again, you should be fine.
If you use
eslint-plugin-flowtype, you will get an error like
don't use any like when you are in the strict mode of
TypeScript. Simply disable ESLint check for the folder via creating a
.eslintignore file in the root of that project and add
flow-typed/ to it.
Now you are good to go. :)