Closed dlindenkreuz closed 7 years ago
What's import type { Predicate } from "lodash"
about?
That statement imports the type definition from the community-maintained flow-typed
repository, in particular from this file: https://github.com/flowtype/flow-typed/blob/master/definitions/npm/lodash_v4.x.x/flow_v0.28.x-/lodash_v4.x.x.js
It looks like it's coming from the "lodash" package though. How can I distinguish between the two? (I'm not a flow type user so you'll have to walk me through it).
Lodash type definitions become implicitly available for the lodash
module through the declare module "lodash"
statement inside of the flow type declaration file.
This works automatically (without import type { foo } from "lodash"
in the user's code) for lodash's own methods because the definitions are exported here explicitly. However, I need to use the Predicate
type which is declared as part of the module, but not in the "default" export of the flow definition file.
Hence my named import statement which in turn causes trouble with babel-plugin-lodash
. Flow is happy with this and checks my types correctly.
You can find more information about the implicit availability of type declarations in the official Flow docs (check out the last section for a specific lodash example).
I'll see if Babel makes a distinction in its AST. If not then you're out of luck.
Update: Patched :tada: :tada:
When using the Flow type definitions for lodash from
flow-typed/npm
, webpack builds fail with the following error message:findCountry.js:
NB: I use
babel-plugin-transform-flow-strip-types
.