此功能是为JavaScript和TypeScript添加的 使用VS Code 1.24
VS Code附带内置支持,用于淡化JavaScript和TypeScript中未使用的本地/参数/导入。您可以通过启用/禁用此功能 设置 :
// For all languages (it is enabled the default) "editor.showUnused": true // Or just for a specific language "[typescript]": { "editor.showUnused": true }
扩展程序还可以添加对其他语言的支持。
您还可以通过设置将未使用的变量标记为警告 noUnusedLocals 和/或 noUnusedParameters 在你的 jsconfig 要么 tsconfig :
noUnusedLocals
noUnusedParameters
jsconfig
tsconfig
{ "compilerOptions": { "noUnusedLocals": true, "noUnusedParameters": true }, "exclude": [ "node_modules", "**/node_modules" ] }
除了将它们变灰之外,这会为未使用的变量添加一个波浪形和错误:
不要忘记选择语言模式。
使用正确的规则更新项目文件夹中的tslint.json文件:
{ "rules": { "no-unused-variable": true, ......... ......... } }
还要在vscode中验证:
"typescript.autoImportSuggestions.enabled": true
未使用的导入将被报告为警告。 tslint中的更多信息 文件 。
我认为你需要等待一段时间,因为他们有计划尽快发布。
查看此链接 的 Suggestion: Show unused imports in VS Code Editor as grayed #8165 强>
Suggestion: Show unused imports in VS Code Editor as grayed #8165