should you publish your flow-typed folder to NPM?

2019-07-28 06:39发布

问题:

I'm wondering if and under what conditions you should publish your flow-typed folder to NPM in your packages. Perhaps (and what I've been thinking) the answer is never, and it's up to application developers to use flow-typed themselves, but perhaps flow-typed install only picks up definitions for dependencies they have declared themselves, rather than dependencies within packages.

So in short, if your package has non-peer flow-typed dependencies, should I be publishing my flow-typed folder or I should I npmignore it?

回答1:

You should never publish this folder. I don't think anything bad will happen if you do publish it, besides just unnecessarily increasing your package size. But nothing good will happen either.

The point of flow-typed is that if you use those library definitions, Flow does not have to check the library code. Instead, it takes the library definitions as given. If I consume your library, Flow in my project is not type checking your library. Therefore, it does not need to know anything about your dependencies.

Of course, this hinges upon you publishing your library interface to flow-typed as well. Unfortunately, the tools do not yet exist to make this easy, but it is the correct thing to do. If you just publish your source to npm, clients may be using a different version of Flow than you used, and so they may see unactionable error messages that are simply due to version differences (since nearly every Flow release is a breaking change). You may also have different .flowconfig options which could result in errors even if the Flow version matches.