How to configure mapbox-gl-js types with flow?

Viewed 265

So I'm using "mapbox-gl": "0.50.0" and // @flow in a react project.

However, when I run flow, it gets into a lot of type errors.

Do I need to add a rule to .flowconfig or how do I configure it?

If I add this to my .flowconfig

[ignore]
.*/node_modules/@mapbox/.*
.*/node_modules/mapbox-gl/.*

Then an error is raised when I try to import mapbox-gl in my actual code

Thanks!

1 Answers

You need to add mapbox-gl into [libs] section like this:

[libs]
./node_modules/mapbox-gl/flow-typed
./node_modules/mapbox-gl/dist/mapbox-gl.js.flow

You may also want to ignore some mapbox-gl dependencies:

[ignore]
.*/node_modules/jsonlint-lines/.*
.*/node_modules/@mapbox/jsonlint-lines-primitives/.*

Just for reference, my .flowconfig file looks like this:

[ignore]
.*/node_modules/jsonlint-lines/.*
.*/node_modules/@mapbox/jsonlint-lines-primitives/.*

[include]

[libs]
./flow-typed
./node_modules/mapbox-gl/flow-typed
./node_modules/mapbox-gl/dist/mapbox-gl.js.flow

[options]
esproposal.class_static_fields=enable
esproposal.class_instance_fields=enable

[lints]

It works for me with mapbox-gl v0.51.0, and flow-bin v0.86.0

Related