有没有办法检测 Typescript 中未使用的变量(类似于 Javascript 中的 ESLint)?
问问题
13683 次
3 回答
56
从 2.0 版开始,Typescript 内置支持检测未使用的局部变量和参数。编译器标志如下:
--noUnusedLocals Report Errors on Unused Locals.
--noUnusedParameters Report Errors on Unused Parameters.
于 2016-07-14T21:10:46.200 回答
12
您可以改用 TSLint。
https://palantir.github.io/tslint/
有一个规则:https ://palantir.github.io/tslint/rules/no-unused-variable/
编辑:
尽管这可行,但如果您使用的是 TypeScript 2 +,则其他答案中提到的编译器标志/选项。
于 2016-05-25T15:21:17.933 回答
11
tsconfig.json
您还可以通过更新项目文件以包含noUnusedLocals
和来检测 Typescript 中未使用的变量noUnusedParameters
:
{
"compilerOptions": {
"noUnusedLocals": true,
"noUnusedParameters": true
}
}
于 2019-02-26T20:01:25.847 回答