“'React' 在定义之前就被使用了。” eslint 警告

all*_*62x 5 javascript reactjs eslint

StackOverflow上的这篇文章类似的问题,但在尝试了我在互联网上可以找到的所有内容后,我似乎无法摆脱此警告。Github 问题。

 Line 1:8:  'React' was used before it was defined  @typescript-eslint/no-use-before-define
Run Code Online (Sandbox Code Playgroud)

我试过将这些添加到规则中,.eslintrc.json但似乎都没有删除警告。

 "no-use-before-define": "off",
 "@typescript-eslint/no-use-before-define": "off"

 "no-use-before-define": [0],
 "@typescript-eslint/no-use-before-define": [1]
Run Code Online (Sandbox Code Playgroud)

这个问题在我的其他项目中不存在。我试过从其他项目复制package.json.eslintrc.json重新安装node_modules,但它仍然存在。

有没有人有任何其他建议来解决警告?提前致谢!

aer*_*min 6

那是因为:

这是很常见的事情,因为 TypeScript 添加了 ESLint 不知道的新功能。第一步是在此处检查我们的“扩展”规则列表。扩展规则只是扩展基本 ESLint 规则以支持 TypeScript 语法的规则。如果您在那里找到它,请尝试一下,看看它是否适合您。您可以通过禁用基本规则并打开扩展规则来配置它。

因此,请尝试在您的中写入该规则.eslintrc.json

   "no-use-before-define": "off",
   "@typescript-eslint/no-use-before-define": ["error"],
Run Code Online (Sandbox Code Playgroud)

相关链接:

https://github.com/typescript-eslint/typescript-eslint/blob/master/packages/eslint-plugin/docs/rules/no-use-before-define.md

https://github.com/typescript-eslint/typescript-eslint/blob/master/docs/getting-started/linting/FAQ.md#i-am-using-a-rule-from-eslint-core-and-它不能正确使用打字稿代码