eslint无法识别Flow Generator类型

Lui*_*rme 9 generator ecmascript-6 eslint flowtype

我正在使用带有flowtype的eslint.在我决定使用es6发电机之前,它工作得很好.当我导出生成器时,我需要指定返回类型,但是eslint无法识别Generator类型.

export function *gen2(): Generator {
  yield 'test';
}
Run Code Online (Sandbox Code Playgroud)

Eslint显示此错误:'Generator' is not defined.但流程完美.

任何人都知道如何让eslint识别Generator类型?

log*_*yth 12

GeneratorJS中没有全局构造函数,因此ESLint会将其视为未知.您需要将其添加到您.eslintrc的全球,例如

{
  "rules": {},
  "globals": {
    "Generator": true
  }
}
Run Code Online (Sandbox Code Playgroud)

  • 你也可以使用babel-eslint + https://github.com/gajus/eslint-plugin-flowtype +**https://github.com/zertosh/eslint-plugin-flow-vars** (2认同)