繁体   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