簡體   English   中英

tslint不會在* .js文件中檢測到未聲明的變量

[英]tslint does not detect undeclared variable in *.js files

在Visual Code中,並使用tslint來檢查* .ts和* .js文件,.js文件中未檢測到未聲明的變量,因為它們在.ts文件中。

任何想法 ?

如您所見,在兩個文件中都很好地檢測到沒有控制台:.ts和.ts的iterableGGG沒有在ts文件中聲明為=>,並帶有紅色下划線。 但不在js文件中。

注意:從lodash導入只是為了有一個模塊,因此ts文件中的變量不是全局變量。

在此處輸入圖片說明

在此處輸入圖片說明

tslint.json

{
    "defaultSeverity": "error",
    "extends": [
        "tslint:recommended"
    ],
    "jsRules": {},
    "rules": {
        "no-any": false
    },
    "rulesDirectory": []
}

我相信,如果我沒有記錯的話,jsRules應該如下所示。

"jsRules": {
    "no-use-before-declare": true
}

我找到了解決方案。

在TS文件中,未聲明的變量iterableGGG由tsc NOT tslint檢測到,您可以觀察到,因為在VC中,警告/錯誤彈出消息以[ts]而不是[tslint]開頭。 並且當tslint檢測到sth時,會有一個規則名稱(例如:“ no-use-before-declare”),您還可以在CLI中直接執行命令tsc和tslint。 您可以檢查tsc是否引發了此類錯誤。

>tsc
src/examplJS.js(3,19): error TS2552: Cannot find name 'iterableGGG'. Did you mean 'iterable' ?
src/examplTS.js(5,19): error TS2304: Cannot find name 'iterableGGG'.

因此轉到tsc config tsconfig.json,只需將“ checkJs”激活為true,VC還將顯示JS代碼和TS的錯誤

“ allowJs”:true,/ *允許編譯javascript文件。 * /

“ checkJs”:true,/ *報告.js文件中的錯誤。 * /

暫無
暫無

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

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