Flow: Make it easy to ignore a node_module except its type definitions

Created on 7 Dec 2017  路  4Comments  路  Source: facebook/flow

react-navigation internals have flow errors. I want to be able to ignore the internals and just use its flow types to flow check my code by doing this:

[ignore]
.*/node_modules/react-navigation/.*

[include]
.*/node_modules/react-navigation/src/TypeDefinition.js

But because ignores are applied after includes and OCAML regexp doesn't seem support the approaches discussed here [0], I can't think of a clean approach other than completely ignoring the module and copy pasting the type definitions. Suggestions welcome. Thx.

[0] https://stackoverflow.com/questions/406230/regular-expression-to-match-a-line-that-doesnt-contain-a-word

Most helpful comment

I think that Flow should use type definitions from node_modules, but should not print errors if they originate in that folder.

All 4 comments

Perhaps the selectively-include-one-file approach is not quite as simple as suggested above. I mistakenly assumed TypeDefinition would be a leaf in react-navigation's dependency graph, but it in fact imports from other parts of the codebase. Not sure if that would work.

https://github.com/react-community/react-navigation/blob/master/src/TypeDefinition.js#L5

I ended up adding flow-typed/react-navigation.js with something roughly like:

declare module "react-navigation/src/TypeDefinition" {
  declare export type NavigationScreenProp<+S> = any;
}

IMO it's not a great idea to depend on type definitions from dependencies like this. Instead, react-navigation should include it's type definitions in the flowtype/flow-typed repository, where they can be versioned by the library version and by Flow version.

I think that Flow should use type definitions from node_modules, but should not print errors if they originate in that folder.

@samwgoldman: The problem of publishing any definitions to flow-typed repository is that you need to maintain 2 things, all the types you use internally and the definition for your consumers...

Was this page helpful?
0 / 5 - 0 ratings