簡體   English   中英

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

[英]“'React' was used before it was defined.” eslint warning

StackOverflow上的這篇文章類似的問題,但在嘗試了我在互聯網上可以找到的所有內容后,我似乎無法擺脫此警告。 Github 問題。

 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 ,但它仍然存在。

有沒有人有任何其他建議來解決警告? 提前致謝!

那是因為:

這是很常見的事情,因為 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-它不能用打字稿代碼正確工作

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM