Fetch 未被 Flow 覆盖

Fetch not covered by Flow

我正在为抓取 API 和 flowjs 在 react-native 应用程序中的实现而苦苦挣扎。

使用 Nuclide,我可以看到我用来从远程获取数据的 fetch 函数 API 没有被 Flow 涵盖...

是的,如果我 99% 的代码都受到监控也没什么大不了的,但仍然如此。我想了解发生了什么。

我安装了流式。我已经为我的提取创建了一个存根,我可以在 flow-typed/npm/fbjs_vx.x.x.x 中看到它,这里是 :

declare module 'fbjs/lib/fetch' {
  declare module.exports: any;
}

我也尝试下载替代的 ponyfill 或 polyfill 以覆盖该行但没有成功。

如果没有 libdef 已经存在,我怎么能说 "fetch take a string as argument and return a promise" 流?

感谢帮助

更新

这是package.json

{
  "name": "BeerOmatic",
  "version": "0.0.1",
  "private": true,
  "scripts": {
    "start": "node node_modules/react-native/local-cli/cli.js start",
    "test": "jest",
    "flow": "flow",
    "android": "ENVFILE=.env.dev react-native run-android"
  },
  "dependencies": {
    "eslint-config-airbnb-flow": "^1.0.2",
    "eslint-plugin-flowtype": "^2.35.0",
    "fetch-ponyfill": "^4.1.0",
    "flow-typed": "^2.1.2",
    "react": "16.0.0-alpha.12",
    "react-native": "0.46.3",
    "react-native-config": "^0.5.0",
    "react-native-fetch-polyfill": "^1.1.2",
    "react-native-navigation": "^1.1.136",
    "react-redux": "^5.0.5",
    "redux": "^3.7.2",
    "redux-logger": "^3.0.6",
    "redux-thunk": "^2.2.0",
    "whatwg-fetch": "^2.0.3"
  },
  "devDependencies": {
    "babel-cli": "^6.24.1",
    "babel-eslint": "^7.2.3",
    "babel-jest": "20.0.3",
    "babel-preset-flow": "^6.23.0",
    "babel-preset-react-native": "2.1.0",
    "eslint": "^3.19.0",
    "eslint-config-airbnb": "^15.0.2",
    "eslint-plugin-import": "^2.7.0",
    "eslint-plugin-jsx-a11y": "^5.1.1",
    "eslint-plugin-react": "^7.1.0",
    "eslint-plugin-react-native": "^2.3.2",
    "flow-bin": "^0.50.0",
    "jest": "20.0.4",
    "react-test-renderer": "16.0.0-alpha.12"
  },
  "jest": {
    "preset": "react-native"
  }
}

嗯...大多数时候,答案都在文档中...

To declare a global function that should be accessible throughout your project, use the declare function syntax in a libdef file:

flow-typed/myLibDef.js

declare function foo(a: number): string; This tells Flow that any code within the project can reference the foo global function, and that the function takes one argument (a number) and it returns a string.

所以我补充说

declare function fetch (a: string): Promise;

到我的流类型文件夹根目录下的全新 myLibDef.js 文件。 然后令人惊讶的是,我不得不将它添加到我的 .flowConfig(在 libs 部分)。我很确定它是自动的,但是……好吧…… 不管怎样,现在 fetch 被覆盖了! \0/