如何使用flow配置mapbox-gl-js类型?

时间:2018-11-01 20:39:32

标签: mapbox mapbox-gl-js mapbox-gl

所以我在React项目中使用"mapbox-gl": "0.50.0"// @flow

但是,当我运行flow时,会遇到很多类型错误。

我需要向.flowconfig添加规则还是如何配置它?

如果我将此添加到我的.flowconfig

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

然后当我尝试在实际代码中导入mapbox-gl时引发错误

谢谢!

1 个答案:

答案 0 :(得分:3)

您需要像这样将mapbox-gl添加到[libs]部分:

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

您可能还想忽略某些mapbox-gl依赖项:

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

仅供参考,我的.flowconfig文件如下所示:

[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]

它适用于mapbox-gl v0.51.0和flow-bin v0.86.0