【问题标题】:"'React' was used before it was defined." eslint warning“‘React’在定义之前就被使用了。”警告
【发布时间】:2020-12-29 23:44:04
【问题描述】:

this post on StackOverflow 类似的问题,但在尝试了我在互联网上可以找到的所有内容后,我似乎无法摆脱这个警告。 Github Issue.

 Line 1:8:  'React' was used before it was defined  @typescript-eslint/no-use-before-define

我已尝试将这些添加到 .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]

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

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

【问题讨论】:

标签: javascript reactjs eslint


【解决方案1】:

那是因为:

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

所以请尝试在您的.eslintrc.json 中编写该规则:

   'no-use-before-define': 'off',
   '@typescript-eslint/no-use-before-define': ['error'],

相关链接:

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-it-doesnt-work-correctly-with-typescript-code

【讨论】:

    猜你喜欢
    • 2020-12-28
    • 2014-01-14
    • 2023-03-08
    • 2017-06-28
    • 2015-01-02
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-03-28
    相关资源
    最近更新 更多